If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Question Converting a csv file to utf-8

Hi All

I am using the fopen and fgets function to open a csv file loop through the first few records and perform certain task...the problem is when my php script tries to open a non-utf-8 csv, it fails to read it...but if I convert that csv (using an editor) to utf-8 format then my php script works fine.

So what I was wondering is if there is anyway in php to check if a file is non utf-8, if so then convert the file to utf-8 so that I do not have to manually convert the character set.

I don't have time to try it right now, but my guess (and it's really just a guess) is that you may have to read the entire file into a string variable (e.g. with file_get_contents()), process that variable through the MB functions (so that any BOM or similar indicators at the beginning of the file are picked up), then save the converted string as a temporary file that you can then process with fgetcsv().