note 123766 added to function.basename
| From: | stocki dot r at gmail dot com | Date: | Wed, 10 Apr 2019 11:02:41 +0000 |
| Subject: | note 123766 added to function.basename | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-210584@lists.php.net to get a copy of this message | ||
Additional note to Anonymous's mb_basename() solution: get rid of trailing slashes/backslashes!
<?php
function mb_basename($path) {
if (preg_match('@^.*[\\\\/]([^\\\\/]+)([\\\\/]+)?$@s', $path, $matches)) {
return $matches[1];
} else if (preg_match('@^([^\\\\/]+)([\\\\/]+)?$@s', $path, $matches)) {
return $matches[1];
}
return '';
}
echo mb_basename("/etc//"); # "etc"
?>
----
Server IP: 208.43.231.9
Probable Submitter: 185.85.3.142 (proxied: 79.172.252.90)
----
Manual Page -- http://php.net/manual/en/function.basename.php
Edit -- https://master.php.net/note/edit/123766
Del: integrated -- https://master.php.net/note/delete/123766/integrated
Del: useless -- https://master.php.net/note/delete/123766/useless
Del: bad code -- https://master.php.net/note/delete/123766/bad+code
Del: spam -- https://master.php.net/note/delete/123766/spam
Del: non-english -- https://master.php.net/note/delete/123766/non-english
Del: in docs -- https://master.php.net/note/delete/123766/in+docs
Del: other reasons-- https://master.php.net/note/delete/123766
Reject -- https://master.php.net/note/reject/123766
Search -- https://master.php.net/manage/user-notes.php