PHP使用正则表达式来解析查询字符串

mur*_*hna 0 php regex

如何使用preg_match从URL获取查询字符串?

http://www.example.com/imgres?imgurl=http://www.example.com/images/blue-diamond-rings.jpg

如何使用preg_matches上述URL 获取"imgurl" ?

Dan*_*man 7

PHP具有解析URL和查询字符串的功能,您不需要使用正则表达式.

$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'];
Run Code Online (Sandbox Code Playgroud)