1

I got .csv file from client but when I read it with PHP, it show some text can't read. I try to upload and open with google sheet and then export .csv again with google. it work perfect when I read it with php.

Are there any way to convert .csv to .csv UTF8 without using google ? because client will send .csv to server everyday automatic. and then my php script will read and import .csv data into database. please help

Thanks

3
  • I already try with header('Content-Type: text/html; charset=utf-8'); and iconv_set_encoding("internal_encoding", "UTF-8"); , both are doesn't work. Commented Apr 25, 2015 at 13:02
  • Check this answer stackoverflow.com/questions/13298353/… Commented Apr 25, 2015 at 13:02
  • it doesn't work I try to use echo iconv( "Windows-1252", "UTF-8", $data[$c] ) follow their code. it still show unreadable text. Please help Commented Apr 25, 2015 at 14:29

2 Answers 2

1

I found the way, first using:

header('Content-Type: text/html; charset=utf-8');

and we need to find which encode language we use from here

http://destructor.de/charsets/index.htm

My language is Thai so i need to use windows-874. so it should be:

iconv("windows-874", "UTF-8", $data[$c]);

so just using this 2 line

header('Content-Type: text/html; charset=utf-8');
iconv("windows-874", "UTF-8", $data[$c]);

Thank Sumit :)

Sign up to request clarification or add additional context in comments.

Comments

0

You can try to add "BOM" to the beginning of CSV file (ie. three bytes: EF BB BF - https://en.wikipedia.org/wiki/Byte_order_mark). In my experience CSV files with BOM are interpreted well by Excel. Maybe it will help in your case.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.