note 109770 modified in function.basename by danbrown
| From: | danbrown@php.net | Date: | Fri, 31 Aug 2012 15:52:12 +0000 |
| Subject: | note 109770 modified in function.basename by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-190345@lists.php.net to get a copy of this message | ||
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; } ?>
--was--
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.
function mb_basename($path)
{
$separator = " qq ";
$path = preg_replace("/[^ ]/u", $separator."\$0".$separator, $path);
$base = basename($path);
$base = str_replace($separator,"",$base);
return $base;
}
http://php.net/manual/en/function.basename.php