I'm using fopen to read in a csv and fgetcsv开发者_高级运维 to read the csv lines. The csv is encoded as Windows-1252, how do I convert this to UTF-8 so it doesn't cut lines with none standard characters?
So far I've tried the following:
setlocale(LC_ALL, 'en_GB.UTF-8');
and
drupal_convert_to_utf8($csv_line[3], 'Windows-1251'); // (I'm using Drupal 6.16)
Both seem to fail.
you can use iconv for this kind of work.
I do not know the drupal_convert_to_utf8 function, but have a look at mb_convert_encoding.
Try using mb_list_encodings to be sure your implementation supports Windows-1252. If not try using ISO 8859-1, it is basicly the same ( http://en.wikipedia.org/wiki/Windows-1252 ).
You should also make sure your csv actually is in Windows-1252. Try using mb_detect_encoding for this and make use of the strict flag.
精彩评论