我需要在最后一个"/"之前删除每个字符
这是我的网址:
http://www.example.com/highlights/cat/all-about-clothing/
我想只有:
all-about-clothing
Run Code Online (Sandbox Code Playgroud)
谢谢
$str = 'http://www.example.com/highlights/cat/all-about-clothing/';
echo basename($str);
// Outputs: all-about-clothing
Run Code Online (Sandbox Code Playgroud)
编辑:
另一种方案:
$str = 'http://www.example.com/highlights/cat/all-about-clothing/';
$path = pathinfo($str, PATHINFO_BASENAME);
echo "<br/>" . $path;
Run Code Online (Sandbox Code Playgroud)