如何在斜线后取一个字符串?

时间:2011-05-17 20:42:09

标签: php string url var

像:

"http://www.blog-name.com/search/taio cruz"
---------------------------------------------^
"Sorry, no posts were found with the tag taio cruz"

问题:

如果用户输入http://www.blog-name.com/search/taio cruz,浏览器会查找名为“taio cruz”的文件夹,不是吗?

如何获得“Taio Cruz”的价值?

3 个答案:

答案 0 :(得分:5)

echo basename("http://www.blog-name.com/search/taio cruz"); //taio cruz

答案 1 :(得分:4)

$url = 'http://www.blog-name.com/search/taio cruz';
$val = end(explode('/', $url));
// $val is now 'taio cruz'

答案 2 :(得分:2)

$url = 'http://www.blog-name.com/search/taio cruz';
$last = substr($url, strrpos($url, '/') + 1);
//$last is now "taio cruz"