View Single Post

  #1 (permalink)  
Old 05-11-2008
Chuck Anderson
 
Posts: n/a
Default fread and UTF-16 encodings

I am having trouble reading files that are using UTF-16 encoding.

I noticed this when I started trying to read an xml file produced by
Winamp. And now I see it in the id3tags of files created by Winamp as well.

When I use fread to get the file contents (a playlist), I get this:

ÿþ<�?�x�m�l� �v�e�r�s�i�o�n�=�"�1�.�0ï¿ ½"� �e�n�c�o�d�
i�n�g�=�"�U�T�F�-�1�6�"�?�>�<�p�l�a�y�l�iï¿ ½s�t�s� �p�l
�a�y�l�i�s�t�s�=�"�7�"�>ï¿ ½<�p�l�a�y�l�i�s�t� �f�i�l�e�
n�a�m�e�=�"�p�l�f�2�2�C�Dï ¿½.�m�3�u�8�"� ....

(I have wrapped that text manually)

When I pass that string to xml_parse, however, it properly decodes it
and gives me this:

<PLAYLISTS PLAYLISTS="7"><PLAYLIST FILENAME="plf22CD.m3u8 ....

How do I detect when file data is encoded like this, and then how should
I work with it?

I have found utf16_decode on the php.net site, but when I use that
function I get an empty string.

--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
Nothing he's got he really needs
Twenty first century schizoid man.
***********************************

Reply With Quote