5
如何获得在php中使用preg_match提到的正则表达式in this article?Url在PHP中使用Gruber的正则表达式匹配
<?php
preg_match("\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))/i", $text, $matches);
print_r($matches);
?>
使用上面的代码,我收到以下错误:
Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash...
请注意,这个正则表达式将允许URL像'http:// 。/'和'http:// ?? /'。如果这对你来说不是问题,你应该真的使用'filter_var('http://www.google.com/',FILTER_VALIDATE_URL)',因为它是一个内置的PHP函数。 – 2010-12-03 13:29:00