Unrecognized extra characters in file parsed with php
I've got a csv file I'm parsing with PHP. (Actually, it's ta开发者_JS百科b-separated.) In a text editor, the file looks like this:
Object Id Page/Master Id Page/Master Name ...
Using this code:
$f = file_get_contents($filepath);
echo $f;
I get this in the browser:
��O�b�j�e�c�t� �I�d� �P�a�g�e�/�M�a�s�t�e�r� �I�d� �P�a�g�e�/�M�a�s�t�e�r� �N�a�m�e� ...
with all those question mark characters. If I use strlen() to count the number of chars, it reports twice as many as it should. I suspect it has something to do with unicode, but I'm not sure how to handle it.
Any ideas?
I may be wrong, but this smells like an UTF-16 encoded file. Can you try
$f = iconv("utf-16", "utf-8", $f);
?
精彩评论