可能重复:
PHP Get end string on url between/and /PHP获取URL的最后一个字返回空白
我有这样的代码来获得的URL的最后一部分/和/结尾。
的网址是:
http://mydomain.com/category/mobile/
我需要从中检索 “手机”。
我使用的代码是:
$url = trim($url, '/');
//Put it in a variable
$the_category = substr($url, strrpos($url, '/'));
//whats in it?
echo $the_category;
以上的回报没有什么...任何想法?
我想你的代码,它打印'/移动' – flowfree
我只是通过设置$ url =“http://mydomain.com/category/mobile/”并且它工作正常。按预期返回/移动。 – EmmanuelG
Working http://codepad.org/f5dhMGAw –