- fgetcsv: documentation ( source)
- unlink: documentation ( source)
- dechex: documentation ( source)
- setlocale: documentation ( source)
- file_put_contents: documentation ( source)
- ord: documentation ( source)
- fopen: documentation ( source)
<?php
setlocale(LC_ALL,'C');
$utfchar = chr(0xC3).chr(0x89); // U+009C in UTF-8
$csv = $utfchar."x".$utfchar."x\n";
file_put_contents('test.csv', $csv);
$file = fopen('test.csv', 'r');
$data = fgetcsv($file);
for ($i = 0; $i < strlen($data[0]); $i++) {
echo dechex(ord($data[0][$i])).' ';
}
echo "\n";
unlink('test.csv');
// expected: c3 89 78 c3 89 78 - "ÉxÉx"
// actual: 78 c3 89 78 - "xÉx"