2

When i split a csv file with my php script i can not see the greek language characters! Could you please help me to convert them? data will be saved in the csv.

<?
$path="book.csv";
if (($handle = fopen("$path", "r")) !== FALSE) {
    while (($info = fgetcsv($handle, 1000, ",")) !== FALSE) {
    print_r($info);
    echo "<br>";
  }
}
?>

DEMO

the question mark is actually the greek words. please help me thank you

Rose
  • 21
  • 1
  • What is the codepage of the Source CSV ? – renick Jan 31 '11 at 09:05
  • What is the charset of your CSV file? – Jake N Jan 31 '11 at 09:09
  • http://galtech.org/test/csv/book.csv i didn't specify any charset – Rose Jan 31 '11 at 09:12
  • You made a mistake saving that .csv file. When the export dialog comes up, select the UTF-8 charset. – mario Jan 31 '11 at 09:15
  • Confirm. the CSV file does not contain Greek. The question marks are just that : 0x3F ASCII – renick Jan 31 '11 at 09:27
  • There are known bugs with fgetcsv() and non-ASCII characters, particularly at the beginning of unquoted values. See http://stackoverflow.com/questions/2238971/fgetcsv-ignores-special-characters-when-they-are-at-the-beginning-of-line – eswald Jan 26 '12 at 20:14

1 Answers1

0

You need to send the correct charset in the content-type HTTP header - which is the same charset the CSV has been saved with. You can also convert the csv data from the original encoding to UTF-8 using mb_convert_string or iconv.

cweiske
  • 30,033
  • 14
  • 133
  • 194