note 71284 added to function.explode
| From: | erelsgl dot NOSPAM at cs dot technion dot ac dot il | Date: | Tue, 21 Nov 2006 09:15:26 +0000 |
| Subject: | note 71284 added to function.explode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-119920@lists.php.net to get a copy of this message | ||
If you want to split a path into name+extension, explode(".",$path,1) will not work,
because if path contains more than one dot, then all dots will be included in the extension.
Here is the solution I found (it returns the last dot with the extension):
<?php
function split_name_and_extension($path) {
if (preg_match('/(.+)(\..*)$/', $path, $matches)) {
array_shift($matches); // return $matches[1], $matches[2]
return $matches;
}
else {
return array($path, "");
}
}
?>
----
Server IP: 192.117.122.43
Probable Submitter: 89.138.178.225
----
Manual Page -- http://www.php.net/manual/en/function.explode.php
Edit -- https://master.php.net/note/edit/71284
Del: integrated -- https://master.php.net/note/delete/71284/integrated
Del: useless -- https://master.php.net/note/delete/71284/useless
Del: bad code -- https://master.php.net/note/delete/71284/bad+code
Del: spam -- https://master.php.net/note/delete/71284/spam
Del: non-english -- https://master.php.net/note/delete/71284/non-english
Del: in docs -- https://master.php.net/note/delete/71284/in+docs
Del: other reasons-- https://master.php.net/note/delete/71284
Reject -- https://master.php.net/note/reject/71284
Search -- https://master.php.net/manage/user-notes.php