Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.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
使用Gruber';PHP中的正则表达式_Php_Regex_Url_Preg Match_Gruber - Fatal编程技术网

使用Gruber';PHP中的正则表达式

使用Gruber';PHP中的正则表达式,php,regex,url,preg-match,gruber,Php,Regex,Url,Preg Match,Gruber,如何让上面提到的正则表达式在php中使用preg_match <?php preg_match("\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))/i", $text, $matches); print_r($matches); ?> 试试这个: preg_match("#\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[

如何让上面提到的正则表达式在php中使用preg_match

<?php
preg_match("\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))/i", $text, $matches);
print_r($matches);
?>
试试这个:

preg_match("#\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))#i", $text, $matches);
preg\u match(“#\b([\w-]+:/?| www[.])[^\s()+(?:\([\w\d]+\)|([^[:punch:[\s]./))| i”,$text,$matches);

您缺少正则表达式分隔符(通常是
/
,但在这里使用
#
,因为它更方便URL)

请注意,此正则表达式将允许类似
http://./
http://?//
。如果这对您来说不是问题,那么您应该真正使用
filter\u var('http://www.google.com/,过滤(验证URL)
,因为它是一个内置的PHP函数。
preg_match("#\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))#i", $text, $matches);