note 109770 deleted from function.basename by googleguy
| From: | googleguy@php.net | Date: | Sat, 12 Jan 2013 09:47:31 +0000 |
| Subject: | note 109770 deleted from function.basename by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-192965@lists.php.net to get a copy of this message | ||
Note Submitter: timo at hotmail dot com
----
Because basename() is locale dependent, I tested to surround each character with a separator before
running basename() and removing separators afterwards. This function can determine basename despite
of locale.
<?php
function mb_basename($path)
{
$separator = " qq ";
$path = preg_replace("/[^ ]/u", $separator."\\$0".$separator, $path);
$base = basename($path);
$base = str_replace($separator,"",$base);
return $base;
}
?>