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? Link to comment https://forums.phpfreaks.com/topic/138045-how-to-create-a-file-with-default-charset-utf-8/ 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. Link to comment https://forums.phpfreaks.com/topic/138045-how-to-create-a-file-with-default-charset-utf-8/#findComment-721520 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! Link to comment https://forums.phpfreaks.com/topic/138045-how-to-create-a-file-with-default-charset-utf-8/#findComment-721532 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"); Link to comment https://forums.phpfreaks.com/topic/138045-how-to-create-a-file-with-default-charset-utf-8/#findComment-721551 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. Link to comment https://forums.phpfreaks.com/topic/138045-how-to-create-a-file-with-default-charset-utf-8/#findComment-721726 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.