PHP using regular expression to parse query string
H开发者_开发问答ow do I use preg_match to get a query string from a URL?
http://www.example.com/imgres?imgurl=http://www.example.com/images/blue-diamond-rings.jpg
How do I get 'imgurl' using preg_matches
from the above URL?
PHP has functions for parsing URLs and query strings, you don't need to use a regular expression.
$parts = parse_url("http://www.mysite.com/imgres?imgurl=http://www.mysite.com/images/blue-diamond-rings.jpg");
$query_string = $parts['query'];
parse_str($query_string, $output);
echo $output['imgurl'];
精彩评论