note 58542 modified in function.fgetcsv by danbrown
| From: | danbrown@php.net | Date: | Sun, 17 May 2009 18:16:15 +0000 |
| Subject: | note 58542 modified in function.fgetcsv by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-155089@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.
<?php
while ( $data = fgetcsv($database, 32768, "|") )
{
$i = 0;
while(isset($data[$i]))
{
$data[$i] = rtrim($data[$i]);
$i++;
}
// ....
}
?>
--was--
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++;
}
....
}
http://php.net/manual/en/function.fgetcsv.php