物理截取
1 $file = '/www/htdocs/inc/lib.inc.php';
2
3 $filename = basename($file);
4 echo $filename, '<br/>';// lib.inc.php
5
6 $filename = str_replace(strrchr($filename, '.'), '', $filename);
7 echo $filename, '<br/>';// lib.inc
使用pathinfo($path, $options)
1 $file = '/www/htdocs/inc/lib.inc.php';
2 $path_parts = pathinfo($file);
3
4 echo '目录名称' . $path_parts['dirname'], '<br/>'; // /www/htdocs/inc
5 echo '文件全名' . $path_parts['basename'], '<br/>'; // lib.inc.php
6 echo '文件后缀' . $path_parts['extension'], '<br/>';// php
7 echo '文件名称' . $path_parts['filename'], '<br/>'; // lib.inc // PHP >= 5.2.0
8
9
10 echo '目录名称' . pathinfo($file, PATHINFO_DIRNAME), '<br/>'; // /www/htdocs/inc
11 echo '文件全名' . pathinfo($file, PATHINFO_BASENAME), '<br/>'; // lib.inc.php
12 echo '文件后缀' . pathinfo($file, PATHINFO_EXTENSION), '<br/>';// php
13 echo '文件名称' . pathinfo($file, PATHINFO_FILENAME), '<br/>'; // lib.inc // PHP >= 5.2.0