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"
?>