PHP 文件路径获取文件名

物理截取

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
复制代码

 

posted on   你看我哪里像好人  阅读(3233)  评论(0)    收藏  举报

< 2025年7月 >
29 30 1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31 1 2
3 4 5 6 7 8 9

导航

统计

点击右上角即可分享
微信分享提示