When writing to a file, I noticed that some file which where utf-8, change to ANSI encoding (and thus becoming corrupt and useless).
This is the code I use to write to the file:
$fp = fopen($target_file, "wb");
fputs($fp, $string, strlen($string));
fclose ($fp);
I thought maybe the string itself might determen if the file becomes utf-8, like if string is chinese or japanese. But even writing something a simple 'soup' to the file makes it change from utf-8 to ANSI.
How to keep the file utf-8 when writing to it?