note 105110 added to function.fputcsv
| From: | OvidiuCurcan at osu1 dot php dot net | Date: | Thu, 28 Jul 2011 10:48:07 +0000 |
| Subject: | note 105110 added to function.fputcsv | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-181953@lists.php.net to get a copy of this message | ||
Unexpected (to me) behaviour: the enclosure characters inside the strings are doubled *unless*
they're preceded by a backslash. If the enclosure is preceded by a backslash it's
considered to be already escaped.
<?php
$data = array(
'Doubled: -> " <-',
'NOT doubled: -> \" <-',
);
$buffer = fopen('php://temp', 'r+');
fputcsv($buffer, $data);
rewind($buffer);
$csv = fgets($buffer);
fclose($buffer);
echo $csv; // "Doubled: -> "" <-","NOT doubled: -> \"
<-"
?>
As a result, the CSV file generated by my application was not correctly opened by OpenOffice.org.
The offending row and all the subsequent rows were missing from the spreadsheet.
PHP: 5.3.2-1ubuntu4.9
OpenOffice.org: 3.2.0
----
Server IP: 69.147.83.197
Probable Submitter: 83.161.137.2
----
Manual Page -- http://www.php.net/manual/en/function.fputcsv.php
Edit -- https://master.php.net/note/edit/105110
Del: integrated -- https://master.php.net/note/delete/105110/integrated
Del: useless -- https://master.php.net/note/delete/105110/useless
Del: bad code -- https://master.php.net/note/delete/105110/bad+code
Del: spam -- https://master.php.net/note/delete/105110/spam
Del: non-english -- https://master.php.net/note/delete/105110/non-english
Del: in docs -- https://master.php.net/note/delete/105110/in+docs
Del: other reasons-- https://master.php.net/note/delete/105110
Reject -- https://master.php.net/note/reject/105110
Search -- https://master.php.net/manage/user-notes.php