删除最后一个/在URL之前的所有字符

Kah*_*din 4 php

我需要在最后一个"/"之前删除每个字符

这是我的网址:

http://www.example.com/highlights/cat/all-about-clothing/

我想只有:

all-about-clothing
Run Code Online (Sandbox Code Playgroud)

谢谢

Pup*_*pil 7

使用basename()

$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)