I want to write to a text file. When I use substr_replace() in PHP, the encoding changes. It doesn't print Greek Characters correctly. If I don't, everything is fine. How can I fix this?
<?php
$file = "test.txt";
$writeFile = fopen($file, "w+"); // Read/write
$myarray = array("δφδφ", "δφδσφδσ", "δφδφδ");
$myarray[0] = substr_replace($myarray[0], "ε", 0, 1);
foreach ($myarray as $data) {
fwrite($writeFile, $data . "\n");
}
?>
Outcome
ε�φδφ
δφδσφδσ
δφδφδ
Outcome without any substr_replace()
δφδφ
δφδσφδσ
δφδφδ
substr_replace
only works on the data as a binary string - without caring for encoding.