0

I have the problem with the php function fgetcsv() .

Lets start from the begin . I want to export csv files in ISO encoding and upload csv . With the export csv i dont have problem but with upload csv i have . This code runs perfect when i have not special characters . If i have greek characters he cannot read it and print NULL. If you can find me a solution !!!

Thanks for your time !!!

$csv = array(); $keys = array();
if (($handle = fopen($uploadedcsv, "r")) !== FALSE) {          
    while (($lines = fgetcsv($handle, 0, $delimiter)) !== FALSE) {                    
        if ($row == 0) {
            utf8_encode($keys);
             utf8_encode($lines);
             mb_convert_encoding($keys,'ISO-8859-15','utf-8');
             mb_convert_encoding($lines,'ISO-8859-15','utf-8');
            $keys = $lines;                        
        } else {
            utf8_encode($keys);
             utf8_encode($lines);
             mb_convert_encoding($keys,'ISO-8859-15','utf-8');
             mb_convert_encoding($lines,'ISO-8859-15','utf-8');
            $csv[] = array_combine($keys, $lines);                        
        }                    
        $row++;
    }
    fclose($handle);`
Marc B
  • 356,200
  • 43
  • 426
  • 500
John Memb
  • 23
  • 2
  • 3
  • 7
  • 1
    "iso encoding"? no such thing. there's various iso standards for encoding formats of text data, but "iso encoding" is like saying "hamburger flavor". mcdonalds? burger king? wendy's? – Marc B Feb 24 '13 at 20:50
  • Don't randomly convert encodings. Read about what `utf8_encode` does before using it. Be clear about what encoding your content is in before doing anything with it. – deceze Feb 24 '13 at 20:52
  • What you're probably bumping up against is that `fgetcsv` is locale sensitive. You need to, for instance, `setlocale(LC_ALL, 'en_US.UTF-8')` before using `fgetcsv`, but that requires you to know what encoding exactly you're dealing with. It also requires you to treat the data correctly afterwards (no `utf8_encode`). – deceze Feb 24 '13 at 20:54
  • like this ? if (($handle = fopen($uploadedcsv, "r")) !== FALSE) { setlocale(LC_ALL, 'en_US.UTF-8'); – John Memb Feb 25 '13 at 08:16

0 Answers0