[thelist] Odd Behavior last night with MySQL Server

Burhan Khalid thelist at meidomus.com
Tue Aug 10 01:56:58 CDT 2004


Hassan Schroeder wrote:
> Rob Smith wrote:
> 
>> Hassan. Let me put it in this light, and maybe you'll see what I see.
> 
> 
>> remember, I'm parsing from a text file and lines.
>>
>> My newer version looks like this
>> 47|"Home"|"Books"|"Audiobooks"|"Movies, Music & Entertainment"|""
>> $line = explode("|",stripslashes($contents[$i]));
> 
> 
> Ah, OK -- I don't do PHP so I didn't recognize "explode" :-)
> 
> But just for future reference -- won't you still have a problem if
> a given line "explodes" to fewer than the required number of columns?
> 
> You might want to add an array-length check, and pad to the required
> number of fields if necessary.
> 
> Or use LOAD DATA INFILE on your raw CSV file, of course.

I guess no one has heard of fgetcsv() :)

" Similar to fgets() except that fgetcsv() parses the line it reads for 
fields in CSV format and returns an array containing the fields read. 
The optional third delimiter  parameter defaults as a comma, and the 
optional enclosure defaults as a double quotation mark. Both delimiter 
and enclosure are limited to one character. If either is more than one 
character, only the first character is used."

http://www.php.net/fgetcsv



More information about the thelist mailing list