note 47021 added to function.fgetcsv

From: Date: Sat, 30 Oct 2004 22:54:48 +0000
Subject: note 47021 added to function.fgetcsv
Groups: php.notes 
Request: Send a blank email to php-notes+get-79380@lists.php.net to get a copy of this message
In "php at dogpoop dot cjb dot net" post, I would change in his function: function csv_split($line,$delim=',',$removeQuotes=true) this code: if ($line[$i+1] == '"') { to: if ($i+1 < strlen($line) && $line[$i+1] == '"') { The reason is that if the quote (") is at the last line of the string, then it will try to reach an undefined space in the string, therefore giving a PHP error. Of course his function is great if your line is a true compatible csv line, but I leave that to you to judge if you can do this assumption ;-) ---- Manual Page -- http://www.php.net/manual/en/function.fgetcsv.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+47021 Delete -- http://master.php.net/manage/user-notes.php?action=delete+47021&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47021&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47021&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47021&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47021&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47021&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+47021&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#79380) next »