note 58542 added to function.fgetcsv
| From: | tokai at binaryriot dot com | Date: | Mon, 07 Nov 2005 22:18:28 +0000 |
| Subject: | note 58542 added to function.fgetcsv | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-98213@lists.php.net to get a copy of this message | ||
Newer PHP versions handle cvs files slightly different than older versions.
"Max Mustermann"|"Muster Road 34b"|"Berlin" |"Germany"
"Sophie Master" |"Riverstreet" |"Washington"|"USA"
The extra spaces behind a few fields in the example (which are useful, when you manually manage a
small csv database to align the columns) were ignored by fgetcsv from PHP 4.3. With the new 4.4.1
release they get appended to the string, so you end up with "Riverstreet " instead the
expected "Riverstreet".
Easy workaround is to just trim all fields after reading them in.
while ( $data = fgetcsv($database, 32768, "|") )
{
$i = 0;
while(isset($data[$i]))
{
$data[$i] = rtrim($data[$i]);
$i++;
}
....
}
----
Manual Page -- http://www.php.net/manual/en/function.fgetcsv.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+58542
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+58542&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+58542&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+58542&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+58542&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+58542&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+58542&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+58542&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+58542&report=yes
Search -- http://master.php.net/manage/user-notes.php