Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP使用正则表达式解析查询字符串_Php_Regex - Fatal编程技术网

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

PHP使用正则表达式解析查询字符串,php,regex,Php,Regex,如何使用preg_match从URL获取查询字符串 如何使用上述URL中的preg\u matches获取“imgurl”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(

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


如何使用上述URL中的
preg\u matches
获取“imgurl”

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