2017-08-27 149 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];