可能重复:
php string function to get substring before the last occurrence of a character
我有字符串
'storage/product/home_decor/living_room/livingroom/7ce3da03b6854283bdd0b8e33b3e556a.11.09.2012.03.42.33.jpg'
如何用/删除最后一个字符串?
我希望我的输出是
'storage/product/home_decor/living_room/livingroom/'
答案 0 :(得分:4)
如果您想保留最后一个/结果,请使用以下代码:
$string = 'storage/product/home_decor/living_room/livingroom/7ce3da03b6854283bdd0b8e33b3e556a.11.09.2012.03.42.33.jpg';
$min = substr($string, 0, strrpos($string, '/') + 1);
echo $min; //output : storage/product/home_decor/living_room/livingroom/
答案 1 :(得分:0)
substr($string, 0, strrpos($string, '/'));