3 回答
TA贡献1876条经验 获得超7个赞
不需要这一切。检查pathinfo(),它为您提供路径的所有组件。
手册中的示例:
$path_parts = pathinfo('/www/htdocs/index.html');
echo $path_parts['dirname'], "\n";
echo $path_parts['basename'], "\n";
echo $path_parts['extension'], "\n";
echo $path_parts['filename'], "\n"; // filename is only since PHP 5.2.0
输出代码:
/www/htdocs
index.html
html
index
或者你只能获得某些部分,如:
echo pathinfo('/www/htdocs/index.html', PATHINFO_EXTENSION); // outputs html
TA贡献1866条经验 获得超5个赞
作为替代方案pathinfo(),您可以使用
basename() - 返回路径的文件名组件
PHP手册中的示例
$path = "/home/httpd/html/index.php";
$file = basename($path); // $file is set to "index.php"
$file = basename($path, ".php"); // $file is set to "index"
你必须提前知道扩展名才能删除它。
- 3 回答
- 0 关注
- 920 浏览
添加回答
举报
