物理截取:
$file = '/www/htdocs/inc/lib.inc.php';$filename = basename($file);echo $filename, '';// lib.inc.php$filename = str_replace(strrchr($filename, '.'), '', $filename);echo $filename, '';// lib.inc
使用pathinfo($path, $options):
$file = '/www/htdocs/inc/lib.inc.php';$path_parts = pathinfo($file);echo '目录名称' . $path_parts['dirname'], ''; // /www/htdocs/incecho '文件全名' . $path_parts['basename'], ''; // lib.inc.phpecho '文件后缀' . $path_parts['extension'], '';// phpecho '文件名称' . $path_parts['filename'], ''; // lib.inc // PHP >= 5.2.0echo '目录名称' . pathinfo($file, PATHINFO_DIRNAME), ''; // /www/htdocs/incecho '文件全名' . pathinfo($file, PATHINFO_BASENAME), ''; // lib.inc.phpecho '文件后缀' . pathinfo($file, PATHINFO_EXTENSION), '';// phpecho '文件名称' . pathinfo($file, PATHINFO_FILENAME), ''; // lib.inc // PHP >= 5.2.0