doujiaohuo1096 2014-01-21 13:16
浏览 37
已采纳

PHP如何删除最后一个斜杠之间的子串?

Here is my string:

test-e2e4/folder1/folder2/6.png.

I want to remove the last part of it, so it should look like this:

test-e2e4/folder1/folder2/

How can i do that using preg_replace() ?

  • 写回答

2条回答 默认 最新

  • ds355020 2014-01-21 13:20
    关注
    $string = preg_replace('#[^/]*$#', '', $string);
    

    DEMO.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?