note 128960 added to function.str-getcsv
| From: | manngo at main dot php dot net | Date: | Sun, 15 Oct 2023 06:24:44 +0000 |
| Subject: | note 128960 added to function.str-getcsv | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-220919@lists.php.net to get a copy of this message | ||
I canât see this mentioned in the description, but it appears that the fields will be trimmed
slightly of trailing line breaks.
In the following example:
<?php
$string = "\nPHP\r\n,Java\nScript\r\n\r\n,Fortran\n,Cobol\n\n,\nSwift\r\n\r\n\r\n";
$data = str_getcsv($string);
foreach($data as $d) print "[$d]";
/* Result:
================================================
[
PHP][Java
Script
][Fortran][Cobol
][
Swift
]
================================================ */
?>
Youâll see:
- a leading line break is retained; a line break in the rest of the field is also retained
- one trailing line break is removed; any more are retained
- a line break at the end of the string is also removed; this means that two trailing line breaks at
the end are removed
- a line break can be a unix/macos line break (\n) or a windows line beak (\r\n)
Tested on my Macintosh, so Iâm not sure how universal this is.
Among other things, it means you can read the file with the file() function without having to
include the FILE_IGNORE_NEW_LINES flag.
----
Server IP: 45.112.84.4
Probable Submitter: 45.91.157.134 (proxied: 159.196.219.235)
----
Manual Page -- https://php.net/manual/en/function.str-getcsv.php
Edit -- https://main.php.net/note/edit/128960
Del: integrated -- https://main.php.net/note/delete/128960/integrated
Del: useless -- https://main.php.net/note/delete/128960/useless
Del: bad code -- https://main.php.net/note/delete/128960/bad+code
Del: spam -- https://main.php.net/note/delete/128960/spam
Del: non-english -- https://main.php.net/note/delete/128960/non-english
Del: in docs -- https://main.php.net/note/delete/128960/in+docs
Del: other reasons-- https://main.php.net/note/delete/128960
Reject -- https://main.php.net/note/reject/128960
Search -- https://main.php.net/manage/user-notes.php