Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Windows-1252 csv to UTF-8 using PHP

Tags:

php

drupal

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.

like image 814
digital Avatar asked Feb 04 '26 04:02

digital


1 Answers

you can use iconv for this kind of work.

like image 99
Guillaume Lebourgeois Avatar answered Feb 09 '26 17:02

Guillaume Lebourgeois



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!