I have script that reads remote file content and writes it to local server. File contains characters: ąčęėįšųūž. After data insertion into local file, UTF-8 encoding is lost. My script code:
<?php
$data = file_get_contents('remote_file_address');
echo $data; //encoding is ok
$file = dirname(__FILE__) . '/../downloads/data.csv';
file_put_contents($file,$data); //invalid encoding in data.csv file
?>
I also followed the instructions depending this post(How to write file in UTF-8 format?), but still no good.
So what is wrong with that? Any ideas?
file_put_contents($myFile, utf8_encode($myContent));
or setting the BOM likefile_put_contents($myFile, "\xEF\xBB\xBF".$myContent);
? – sofl Jun 20 '12 at 8:31echo file_get_contents(dirname(__FILE__) . '/../downloads/data.csv');
. Is that the case? – Ja͢ck Jun 20 '12 at 8:38