giba Posted December 22, 2008 Share Posted December 22, 2008 Hi there, guys. Hey I got an issue today. I am building a system that creates files on the fly But I must use utf-8 as default charset, because it is used for the most application files. In fact I am doing the basic task. He is the basic code: if(file_exists($file)) { $error = "This is already exists!"; } else { /** * Open the file */ $f= fopen($file,'x+'); /** * Write the new content */ fwrite($f,$content); /** * Close the file */ fclose($f); } How could I generate this file in utf-8? Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted December 22, 2008 Share Posted December 22, 2008 How could I generate this file in utf-8?Assuming that the actual data you want to write includes multi-byte characters, simply write the data to that file. It's the external applications used to read that file that need to support utf-8. Quote Link to comment Share on other sites More sharing options...
giba Posted December 22, 2008 Author Share Posted December 22, 2008 Well, I have done this yet! But to make it clear, When the server creates a file on Windows it does as ANSI. On Linux it does as UTF-8. So when I include a ANSI file inside a UTF-8 it gerenates strange characters. The workaround is manually converting it to utf-8 on Windows with notepad++, on Linux it's all right. But this is an important issue because the application must be cross platform. I will let it as it is! Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted December 22, 2008 Share Posted December 22, 2008 When the server creates a file on Windows it does as ANSI. $fh = fopen("/home/rasmus/file.txt", "wb"); Quote Link to comment Share on other sites More sharing options...
giba Posted December 22, 2008 Author Share Posted December 22, 2008 Sure, that's all right now! I haven't seen this before because I didn't looked at the note inside the PHP manual . The little I used file handling with PHP was that simple. But, yes, in fact it now works perfectly. Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.