如何从URL字符串获取参数? [英] How to get parameters from a URL string?

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

问题描述

我有一个HTML表单字段$_POST["url"],具有一些URL字符串作为值. 值示例为:

I have a HTML form field $_POST["url"] having some URL strings as the value. Example values are:


https://example.com/test/1234?email=xyz@test.com
https://example.com/test/1234?basic=2&email=xyz2@test.com
https://example.com/test/1234?email=xyz3@test.com
https://example.com/test/1234?email=xyz4@test.com&testin=123
https://example.com/test/the-page-here/1234?someurl=key&email=xyz5@test.com

如何从这些URL/值中仅获取email参数?

How can I get only the email parameter from these URLs/values?

请注意,我没有从浏览器地址栏中获取这些字符串.

Please note that I am not getting these strings from browser address bar.

推荐答案

您可以使用 parse_str()

You can use the parse_url() and parse_str() for that.

$parts = parse_url($url);
parse_str($parts['query'], $query);
echo $query['email'];

如果要使用PHP动态获取$url,请查看以下问题:

If you want to get the $url dynamically with PHP, take a look at this question:

获取PHP中的完整URL

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

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