本文介绍了如何从 URL 字符串中获取参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 HTML 表单字段 $_POST["url"]
,有一些 URL 字符串作为值.
示例值为:
https://example.com/test/[email protected]://example.com/test/[email protected]://example.com/test/[email protected]://example.com/test/[email protected]&testin=123https://example.com/test/the-page-here/[email protected]等
如何才能从这些 URL/值中只获取 email
参数?
请注意,我不是从浏览器地址栏中获取这些字符串的.
解决方案
您可以使用 parse_url()
和 parse_str()
为此.
$parts = parse_url($url);parse_str($parts['query'], $query);回声 $query['email'];
如果你想用PHP动态获取$url
,看看这个问题:
I have an HTML form field $_POST["url"]
, having some URL strings as the value.
Example values are:
https://example.com/test/[email protected] https://example.com/test/[email protected] https://example.com/test/[email protected] https://example.com/test/[email protected]&testin=123 https://example.com/test/the-page-here/[email protected]
etc.
How can I get only the email
parameter from these URLs/values?
Please note that I am not getting these strings from the browser address bar.
解决方案
You can use the parse_url()
and parse_str()
for that.
$parts = parse_url($url);
parse_str($parts['query'], $query);
echo $query['email'];
If you want to get the $url
dynamically with PHP, take a look at this question:
这篇关于如何从 URL 字符串中获取参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!