2015-10-11 105 views
-1

我的腳本正在返回以下路徑。爆炸字符串以移除路徑

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

我想刪除的休息和文件名結束。

我知道我必須爆炸字符串,我只是不知道該怎麼去做。

+1

** 「我知道我必須要爆炸字符串」 **其實你不需要'這裏explode'。 –

+1

我的錯誤。我還在學習 :) – DrZ

回答

1

使用basename

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

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