2017-08-27 137 views
-1

如何從下面的字符串中刪除所有斜線?我想要的只是圖像名稱。PHP刪除部分字符串

的字符串是:

listingimages//uPLhHJtvIZ//architecture-1836070__340.jpg 

所有我想要的是

architecture-1836070__340.jpg 

我還是弄不清楚的preg_match和替換。

+0

向我們展示您的preg_match嘗試 – Scuzzy

+0

basename如何? http://php.net/manual/en/function.basename.php – AlexT82

+0

可能重複[如何從路徑中分離文件名? basename()與preg \ _split()與數組\ _pop()](https://stackoverflow.com/questions/20859628/how-to-separate-filename-from-path-basename-versus-preg-split-with -array-PO) – mickmackusa

回答

0

理想假設你想抓住的文件名basename()應該幫助,但仍然只是一個建議與爆炸:d

一個簡單而快速的與爆炸的解決方案:

$image_path ="listingimages//uPLhHJtvIZ//architecture-1836070__340.jpg"; 
$image_name = explode("//",$image_path); 

echo $image_name [count($image_name)-1];