add utf8_basename() as replacement for basename()

This function can handle mutlibyte strings, even if locale is set
to 'C'
This commit is contained in:
Uwe Steinmann 2017-03-03 08:53:26 +01:00
parent 9e1000506d
commit d48ef8b6ba

View File

@ -306,6 +306,27 @@ function dskspace($dir) { /* {{{ */
return $space;
} /* }}} */
/**
* Replacement of PHP's basename function
*
* Because basename is locale dependent and strips off non ascii chars
* from the beginning of filename, it cannot be used in a environment
* where locale is set to e.g. 'C'
*/
function utf8_basename($path, $suffix='') { /* {{{ */
$rpos = strrpos($path, DIRECTORY_SEPARATOR);
if($rpos === false)
return $path;
$file = substr($path, $rpos+1);
$suflen = strlen($suffix);
if($suflen && (substr($file, -$suflen) == $suffix)){
$file = substr($file, 0, -$suflen);
}
return $file;
} /* }}} */
/**
* Log a message
*