I have a short script that reads a CSV file which looks like the following:
$csv = new SplFileObject($pathToFile, 'r');
while (!$csv->eof() && ($row = $csv->fgetcsv()) && $row[0] !== null) {
var_dump($row);
}
This works ok, except it has a problem with some non-standard characters. There are some German-language words in the CSV, and my specific problem is that it has difficulties with umlauts. An example of the type of row it outputs is:
array(5) {
[0]=>
string(6) "J¦rgen"
[1]=>
string(8) "Lastname"
[2]=>
string(14) "name@domain.de"
[3]=>
string(7) "Example"
[4]=>
string(7) "Example"
}
The ü in Jürgen getting replaced with a ¦ character.
I've tried putting the following code before:
mb_internal_encoding('UTF-8');
but it has had no effect.
Opening the csv file in Vi shows the ü successfully, so the file is correct on the server.
Can anyone advise how to PHP successfully handling German characters when parsing a CSV?