PHP 从 URL 字符串获取参数(不是当前页面)
我知道您可以轻松地从当前所在的页面获取参数,但是您可以轻松地从任何 URL 字符串中执行相同的操作吗?
我需要从 https://market.android.com/details?id=com.zeptolab.ctr.paid?t=W251bGwsMSwxLDIxMiwiY29tLnplcHRvbGFiLmN0ci5wYWlkIl0
等字符串中获取“id”参数。
我怎样才能用 PHP 做到这一点?是否有内置函数,或者我必须使用正则表达式?
I know you can easily get a parameter from the page you're currently on, but can you easily do the same from any URL string?
I need to grab the "id" parameter out of a string like https://market.android.com/details?id=com.zeptolab.ctr.paid?t=W251bGwsMSwxLDIxMiwiY29tLnplcHRvbGFiLmN0ci5wYWlkIl0
.
How can I do this with PHP? Is there a built-in function, or do I have to use regex?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以结合使用 parse_url 和 parse_str:
You could use combination of parse_url and parse_str:
是的,你可以。
parse_url()
来自 PHP 文档:
上面的示例将输出:
Yes you can.
parse_url()
From the PHP docs:
The above example will output:
有
parse_url()
:Codepad.org 上 http://codepad.org/mHXnOYlc
There's
parse_url()
:On Codepad.org: http://codepad.org/mHXnOYlc
您可以使用 parse_str(),然后访问变量 $ ID。
You can use parse_str(), and then access the variable $id.