note 105667 deleted from function.fgetcsv by danbrown
| From: | danbrown@php.net | Date: | Tue, 06 Sep 2011 15:32:47 +0000 |
| Subject: | note 105667 deleted from function.fgetcsv by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-182973@lists.php.net to get a copy of this message | ||
Note Submitter: Aaron W
----
It looks like this function has been improved since the note posted by "do not spam aleske at
live dot ru" on 08-Jul-2010 01:38. In PHP 5.3.5, I find that it handles that complicated CSV
example from Wikipedia perfectly, doubled-double-quotes, enclosed newlines, and all.
test.csv:
1997,Ford,E350,"ac, abs, moon",3000.00
1999,Chevy,"Venture ""Extended Edition""","",4900.00
1999,Chevy,"Venture ""Extended Edition, Very
Large""","",5000.00
1996,Jeep,Grand Cherokee,"MUST SELL!
air, moon roof, loaded",4799.00
test.php:
<?php
$f = fopen('test.csv','r');
while( $row = fgetcsv($f) ){
var_dump($row);
}
?>
Output:
array(5) {
[0]=>
string(4) "1997"
[1]=>
string(4) "Ford"
[2]=>
string(4) "E350"
[3]=>
string(13) "ac, abs, moon"
[4]=>
string(7) "3000.00"
}
array(5) {
[0]=>
string(4) "1999"
[1]=>
string(5) "Chevy"
[2]=>
string(26) "Venture "Extended Edition""
[3]=>
string(0) ""
[4]=>
string(7) "4900.00"
}
array(5) {
[0]=>
string(4) "1999"
[1]=>
string(5) "Chevy"
[2]=>
string(38) "Venture "Extended Edition, Very Large""
[3]=>
string(0) ""
[4]=>
string(7) "5000.00"
}
array(5) {
[0]=>
string(4) "1996"
[1]=>
string(4) "Jeep"
[2]=>
string(14) "Grand Cherokee"
[3]=>
string(33) "MUST SELL!
air, moon roof, loaded"
[4]=>
string(7) "4799.00"
}