发布于:2020-04-09 09:42:50
物理截取:
$file = '/www/htdocs/inc/lib.inc.php';
$filename = basename($file);
echo $filename, '<br/>';// lib.inc.php
$filename = str_replace(strrchr($filename, '.'), '', $filename);
echo $filename, '<br/>';// lib.inc
使用pathinfo($path, $options):
$file = '/www/htdocs/inc/lib.inc.php';
$path_parts = pathinfo($file);
echo '目录名称' . $path_parts['dirname'], '<br/>'; // /www/htdocs/inc
echo '文件全名' . $path_parts['basename'], '<br/>'; // lib.inc.php
echo '文件后缀' . $path_parts['extension'], '<br/>';// php
echo '文件名称' . $path_parts['filename'], '<br/>'; // lib.inc // PHP >= 5.2.0
echo '目录名称' . pathinfo($file, PATHINFO_DIRNAME), '<br/>'; // /www/htdocs/inc
echo '文件全名' . pathinfo($file, PATHINFO_BASENAME), '<br/>'; // lib.inc.php
echo '文件后缀' . pathinfo($file, PATHINFO_EXTENSION), '<br/>';// php
echo '文件名称' . pathinfo($file, PATHINFO_FILENAME), '<br/>'; // lib.inc // PHP >= 5.2.0
阅读 403+
10