我的脚本返回以下路径。
/home/vol14_2/project.com/b22_16126933/test.project.com/htdocs/php/api.php
我想删除其余部分并以文件名结束。
我知道我必须爆炸这个字符串,我只是不知道该怎么做。
答案 0 :(得分:1)
使用basename
echo basename("/home/vol14_2/project.com/b22_16126933/test.project.com/htdocs/php/api.php");
//api.php
$path_parts = pathinfo('/home/vol14_2/project.com/b22_16126933/test.project.com/htdocs/php/api.php');
echo $path_parts['basename']; // since PHP 5.2.0
//api.php
答案 1 :(得分:1)
<?php
$path = "/home/vol14_2/project.com/b22_16126933/test.project.com/htdocs/php/api.php";
$file = basename($path); // $file is set to "api.php"
$file = basename($path, ".php"); // $file is set to "api"
?>