update page now

Voting

: min(nine, five)?
(Example: nine)

The Note You're Voting On

michael dot arnauts at gmail dot com
13 years ago
fgetcsv seems to handle newlines within fields fine. So in fact it is not reading a line, but keeps reading untill it finds a \n-character that's not quoted as a field.
Example:
<?php
/* test.csv contains:
"col 1","col2","col3"
"this
is
having
multiple
lines","this not","this also not"
"normal record","nothing to see here","no data"
*/
$handle = fopen("test.csv", "r");
while (($data = fgetcsv($handle)) !== FALSE) {
 var_dump($data);
}
?>

Returns:
array(3) {
 [0]=>
 string(5) "col 1"
 [1]=>
 string(4) "col2"
 [2]=>
 string(4) "col3"
}
array(3) {
 [0]=>
 string(29) "this
is
having
multiple
lines"
 [1]=>
 string(8) "this not"
 [2]=>
 string(13) "this also not"
}
array(3) {
 [0]=>
 string(13) "normal record"
 [1]=>
 string(19) "nothing to see here"
 [2]=>
 string(7) "no data"
}
This means that you can expect fgetcsv to handle newlines within fields fine. This was not clear from the documentation.

<< Back to user notes page

AltStyle によって変換されたページ (->オリジナル) /