note 107640 deleted from function.explode by googleguy
| From: | googleguy@php.net | Date: | Thu, 22 Nov 2012 16:51:28 +0000 |
| Subject: | note 107640 deleted from function.explode by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-192091@lists.php.net to get a copy of this message | ||
Note Submitter: qeremy [atta] gmail [dotta] com
----
If you don't want any empty array element, just use simply "preg_split" instead this
function (or struggle with an extra function, i.e. "trim");
<?php
$uri = "/user/123/";
$tmp = explode("/", $uri);
print_r($tmp);
$tmp = explode("/", trim($uri, "/"));
print_r($tmp);
$tmp = preg_split("~/~", $uri, -1, PREG_SPLIT_NO_EMPTY);
print_r($tmp);
?>
Array
(
[0] =>
[1] => user
[2] => 123
[3] =>
)
Array
(
[0] => user
[1] => 123
)
Array
(
[0] => user
[1] => 123
)