2011-08-22 42 views
2

字符串我有一個字符串:需要幫助切斷與PHP

$str = "http://www.abc.com/xxx/xxx/v54/c505/1.html"; 

如何切後1.html了嗎?

我想要的結果是http://www.abc.com/xxx/xxx/v54/c505/

回答

6

使用dirname()

$newStr = dirname($str) . '/'; 
+0

+1沒有意識到這會起到很好用'HTTP://':) – alex

+0

@alex我回答;-) – Phil

+0

我以前的兩倍測試在分配+1之前檢查你:D – alex

1
$str = substr($str, 0, strrpos($str, '/') + 1); 

CodePad

+0

+1適用於刪除任意分隔的字符串的最後部分 – Phil

+0

@Phil哎呀,修正:) – alex

0

您可以使用目錄名() -

$str = "http://www.abc.com/xxx/xxx/v54/c505/1.html"; 
$dir = dirname($str);