mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-03-12 00:45:34 +00:00
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:
parent
9e1000506d
commit
d48ef8b6ba
|
@ -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
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue
Block a user