【发布时间】:2010-01-08 02:34:24
【问题描述】:
我如何获得提到的正则表达式in this article 与 php 中的 preg_match 一起使用?
<?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...
【问题讨论】:
-
请注意,此正则表达式将允许像
http://./和http://??/这样的 URL。如果这对您来说不是问题,您应该真正使用filter_var('http://www.google.com/', FILTER_VALIDATE_URL),因为它是一个内置的 PHP 函数。
标签: php regex url preg-match gruber