note 125917 added to function.explode
| From: | DavidSpector@php.net | Date: | Fri, 12 Mar 2021 15:16:09 +0000 |
| Subject: | note 125917 added to function.explode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-219323@lists.php.net to get a copy of this message | ||
When using 'explode' to create an array of strings from a user-specified string that
contains newline characters, you may wish the resulting array to correctly reflect the user's
intentions by ignoring any final empty line (many users like to end multi-line input with a final
newline, for clarity).
Here is a function to call after 'explode' to support this effect:
// When using explode, delete the last line in the array of lines when it is empty
function IgnoreEmptyLastLine(&$linesArr)
{
$last=count($linesArr)-1;
if ($last>=0 && !$linesArr[$last])
unset($linesArr[$last]);
} // IgnoreEmptyLastLine
----
Server IP: 45.112.84.4
Probable Submitter: 45.112.85.245 (proxied: 98.2.238.89)
----
Manual Page -- http://php.net/manual/en/function.explode.php
Edit -- https://master.php.net/note/edit/125917
Del: integrated -- https://master.php.net/note/delete/125917/integrated
Del: useless -- https://master.php.net/note/delete/125917/useless
Del: bad code -- https://master.php.net/note/delete/125917/bad+code
Del: spam -- https://master.php.net/note/delete/125917/spam
Del: non-english -- https://master.php.net/note/delete/125917/non-english
Del: in docs -- https://master.php.net/note/delete/125917/in+docs
Del: other reasons-- https://master.php.net/note/delete/125917
Reject -- https://master.php.net/note/reject/125917
Search -- https://master.php.net/manage/user-notes.php