Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
103 views
in Technique[技术] by (71.8m points)

php - How can I get parameters from a URL string?

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/1234?basic=2&[email protected]
https://example.com/test/[email protected]
https://example.com/test/[email protected]&testin=123
https://example.com/test/the-page-here/1234?someurl=key&[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.

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

Get the full URL in PHP


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...