开发者

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'];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜