note 126941 added to function.explode
| From: | Gerben at main dot php dot net | Date: | Sat, 19 Mar 2022 23:53:51 +0000 |
| Subject: | note 126941 added to function.explode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-217743@lists.php.net to get a copy of this message | ||
Note that an empty input string will still result in one element in the output array. This is
something to remember when you are processing unknown input.
For example, maybe you are splitting part of a URI by forward slashes (like
"articles/42/show" => ["articles", "42", "show"]). And
maybe you expect that an empty URI will result in an empty array ("" => []). Instead,
it will contain one element, with an empty string:
<?php
$uri = '';
$parts = explode('/', $uri));
var_dump($parts);
?>
Will output:
array(1) {
[0]=>
string(0) ""
}
And not:
array(0) {
}
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.135 (proxied: 82.73.20.120)
----
Manual Page -- https://php.net/manual/en/function.explode.php
Edit -- https://main.php.net/note/edit/126941
Del: integrated -- https://main.php.net/note/delete/126941/integrated
Del: useless -- https://main.php.net/note/delete/126941/useless
Del: bad code -- https://main.php.net/note/delete/126941/bad+code
Del: spam -- https://main.php.net/note/delete/126941/spam
Del: non-english -- https://main.php.net/note/delete/126941/non-english
Del: in docs -- https://main.php.net/note/delete/126941/in+docs
Del: other reasons-- https://main.php.net/note/delete/126941
Reject -- https://main.php.net/note/reject/126941
Search -- https://main.php.net/manage/user-notes.php