Forum Moderators: coopster

Message Too Old, No Replies

Weird problem reading a csv-file

         

Oliver Henniges

7:25 pm on Nov 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am currently trying to open and read the csv-files generated by google's adwords editor.

It works quite fine to open and swallow the file with either file() or fopen(); but when I print the lines, all data-field-entries are written with an empty-space-character between each single letter, (which you actually can only see in the source-code of the browser output; even opening the file with wordpad or ms-editor did not show these spaces).

Is this a unix-windows problem?
Have I discovered the fnords [en.wikipedia.org]?

I know this is only a minor problem, but I can't figure it out.

Any help is well appreciated (otherwise I am going to loop an delete every second character;)

cameraman

1:35 am on Nov 20, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sounds like it might be unicode.
What does unicode_encode [us3.php.net]($thefile,''ISO-8859-2'') do to it?

Oliver Henniges

9:20 am on Nov 20, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have php 5.0.5 installed. The function doesn't exist and is experimental according to the manuals.

Reason to upgrade?

Oliver Henniges

9:38 am on Nov 20, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I got it:

$csv1 = file($filename);
$csv2 = implode($csv1);
$csv3 = iconv("UTF-16","ISO-8859-1",$csv2);
$csv = explode ("\n",$csv3);

Instead of imploding and exploding I first tried to loop thru the lines, but still got some error-mistakes. Well this works. Thanks for your help, reading the wiki-entry on unicode brought me to the right track.