0

I have a CSV file. If I open it with a standard text editor such as notepad or excel, I can read the strings. But I can't read it with my PHP code (there is a symbols font error). How can I fix it?

My PHP code:

<?php
    $file = fopen("data.csv","r");

    while(! feof($file))
      {
          print_r(fgetcsv($file));
      }

    fclose($file);
 ?>

My CSV file

Thank all! I found the answer http://www.practicalweb.co.uk/blog/2008/05/18/reading-a-unicode-excel-file-in-php/

Sᴀᴍ Onᴇᴌᴀ
  • 8,218
  • 8
  • 36
  • 58

1 Answers1

4

The file encoding appears to be UCS-2 LE, from which UTF-16 developed1. (also see this answer).

Save the file with UTF-8 encoding. Instead of notepad, try using a different text editor like Notepad++. It has a menu for choosing the encoding of the file. Then the PHP code can read the characters as desired. See demo here.


1https://web.archive.org/web/20060114213239/http://www.unicode.org/faq/basic_q.html#23

Sᴀᴍ Onᴇᴌᴀ
  • 8,218
  • 8
  • 36
  • 58