joe25 Posted August 17, 2009 Share Posted August 17, 2009 Hello guys I hope you can help me with this one. Whenever im using rename(),copy() or fwrite() on chinese named files, I get an error or weird results. When Im trying to rename an english named file, for example "work.html" to "指南.html", I get a file named "指å—.html" instead. Here is my code: <? //Used so the chinese characters would show up properly on this page. Remove this and the character encoding goes weird. UTF is the encoding I use for simple chinese characters. ini_set('default_charset', 'UTF-8'); //this really doesn't do anything, just tried to make use of the third value for rename() function $opts = array( 'http'=>array( //'method'=>"GET", 'header'=>"default_charset = UTF-8" ) ); $context = stream_context_create($opts); //Chinese character in hex $xslt_result = "指南"; //Convert the hex to chinese characters $work = html_entity_decode($xslt_result, ENT_NOQUOTES,'UTF-8'); print $work.".html should be the resulting file"; rename("work.html", $work.".html",$context); //OR just - rename("work.html", "指南.html",$context); ?> When I try to use the copy() or fwrite() function I get an error instead. rename() is the only php function that is somewhat working with SIMPLE CHINESE characters. (i mean not traditional) Im using windows vista with XAMPP. I hope someone can help me with this. I would greatly appreciate it. *note: create a blank file named work.html before running my code* Quote Link to comment https://forums.phpfreaks.com/topic/170611-having-problems-with-file-manipulation-which-involves-chinese-named-files/ Share on other sites More sharing options...
oni-kun Posted August 17, 2009 Share Posted August 17, 2009 You have to have an utf8_encode() function within your fwrite command.. Example: //Convert the hex to chinese characters $work = html_entity_decode($xslt_result, ENT_NOQUOTES,'UTF-8'); //$work = utf8_encode($work); print $work.".html should be the resulting file"; rename("work.html", utf8_encode($work).".html",$context); Try and see if that works.. fwrite and rename seem to default to ISO-latin1.. Quote Link to comment https://forums.phpfreaks.com/topic/170611-having-problems-with-file-manipulation-which-involves-chinese-named-files/#findComment-899926 Share on other sites More sharing options...
joe25 Posted August 18, 2009 Author Share Posted August 18, 2009 I got this result instead "指å—.html" Anyway, yes I think that ISO-latin1 is the default encoding for PHP file manipulation functions. I think the third item for the rename() item is the key. I just can't seem to use it right. Quote Link to comment https://forums.phpfreaks.com/topic/170611-having-problems-with-file-manipulation-which-involves-chinese-named-files/#findComment-900744 Share on other sites More sharing options...
thebadbad Posted August 18, 2009 Share Posted August 18, 2009 I tried a bunch of different combinations the other day (also including different stream contexts), and couldn't get it to work. Quote Link to comment https://forums.phpfreaks.com/topic/170611-having-problems-with-file-manipulation-which-involves-chinese-named-files/#findComment-900758 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.