使用Gruber';PHP中的正则表达式
如何让上面提到的正则表达式在php中使用preg_match使用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("\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);