note 125399 added to function.fputcsv
| From: | reinhold dot egenter at gmail dot com | Date: | Wed, 30 Sep 2020 13:05:01 +0000 |
| Subject: | note 125399 added to function.fputcsv | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-215492@lists.php.net to get a copy of this message | ||
Please note, that fputcsv ist not always enclosing strings with the enclosure character.
<?php
$fh = fopen('file.csv', 'w');
$a = [ 'One 1', 'Two', 'Three 3' ];
fputcsv($fh, $a, "\t");
fclose($fh);
?>
results in a file containing the line:
"One 1" Two "Three 3"
It seems that only strings containing at least one of the following characters are enclosed:
- the delimiter character
- the enclosure character
- the escape character
- \n (new line)
- \r (line feed)
- \t (tab)
- blank
I hope this saves you the hour it took me to get to the bottom of this behaviour.
----
Server IP: 45.112.84.4
Probable Submitter: 185.85.3.172 (proxied: 217.24.204.170)
----
Manual Page -- http://php.net/manual/en/function.fputcsv.php
Edit -- https://master.php.net/note/edit/125399
Del: integrated -- https://master.php.net/note/delete/125399/integrated
Del: useless -- https://master.php.net/note/delete/125399/useless
Del: bad code -- https://master.php.net/note/delete/125399/bad+code
Del: spam -- https://master.php.net/note/delete/125399/spam
Del: non-english -- https://master.php.net/note/delete/125399/non-english
Del: in docs -- https://master.php.net/note/delete/125399/in+docs
Del: other reasons-- https://master.php.net/note/delete/125399
Reject -- https://master.php.net/note/reject/125399
Search -- https://master.php.net/manage/user-notes.php