Re: Extra blank lines bomb fgetcsv function

From: Date: Tue, 02 Dec 2003 12:19:05 +0000
Subject: Re: Extra blank lines bomb fgetcsv function
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-31835@lists.php.net to get a copy of this message
In article <20031202005217.76315.qmail@web20505.mail.yahoo.com>, karenresplendo@yahoo.com says... > Here is the beginning of a big loop that loads a line at a time from an uploaded textfile and > then runs validation on each field: > > //////////////////////////////////////////////////////////////////////// > //loop through the rows putting the fields into an array > //////////////////////////////////////////////////////////////////////// > while ($fieldarray = fgetcsv ($handle, $userfile_size, ",")) { > > > The problem I am having is that when there is an empty line at the bottom of the txt file, my > validation tells me it is a bad line, and rejects the file. Is there anyway of stopping the loop, or > trimming the file of empty lines? Hope I've explained my problem correctly. According to the docs, "A blank line in a CSV file will be returned as an array comprising a single null field, and will not be treated as an error." So I imagine you need to apply your validation only where the array != a single null field. Cheers -- Quod subigo farinam A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing on usenet?

« previous php.db (#31835) next »