我按以下方式获取网址:
http://localhost/hi-every-body/
http://s1.localhost/hello-world/
http://s2.localhost/bye-world/
我希望像
一样获取精确的slu ..hi-every-body
hello-world
bye-world
很少检查&很少的代码行。我试过但是出现了太多支票。
答案 0 :(得分:13)
这应该是这样的:
trim(parse_url($url, PHP_URL_PATH), '/');
它需要路径并剥掉两边的斜线。
答案 1 :(得分:0)
一个可能更强大的解决方案是:
$slugs = explode("/", $_GET['params']);
这将为您提供一个数组,其中包含URL中的每个元素。
例如。 http://localhost/one/hippo/cake?t=21
成为数组:
Array (
[0] => one
[1] => hippo
[2] => cake
)
这使您可以根据需要使用每个元素。