PHP从URL路径获取参数 [英] PHP take arguments from URL path

查看:85
本文介绍了PHP从URL路径获取参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有一个这样的网址:

Say I have a url like this:

http://www.mysite.com/forum/board1/sub-forum/topics/123

PHP中是否有一种简单的方法(不能使用HTAccess)来获取该URL并提取board1sub-forumtopics123,因此我可以在数据库中使用它们?是否有任何内置函数,或者我必须编写自己的函数?

Is there a simple way in PHP (can't use HTAccess) to take that URL and extract board1, sub-forum, topics and 123 so I can use them in a database for example? Are there any built in functions or will I have to write my own?

谢谢

詹姆斯

推荐答案

explode('/', getenv('REQUEST_URI'));

如果您的环境恰好在上述值中包含查询字符串部分,请采用以下整洁的解决方法:

If your environment happens to include the query string part in the above value, here's a neat workaround:

explode('/', strtok(getenv('REQUEST_URI'), '?'));

这篇关于PHP从URL路径获取参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆