分解字符串以删除路径

exploding string to remove path

我的脚本返回以下路径。

/home/vol14_2/project.com/b22_16126933/test.project.com/htdocs/php/api.php

我想删除其余部分并以文件名结尾。

我知道我必须爆弦,但我真的不知道该怎么做。

使用basename

echo basename("/home/vol14_2/project.com/b22_16126933/test.project.com/htdocs/php/api.php");
//api.php

pathinfo

$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
<?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"
?>