【发布时间】:2012-04-14 19:02:14
【问题描述】:
很抱歉提出一个问题,但在理解正则表达式代码方面我毫无用处。
在我没有写的一个php模块中是如下函数
function isURL($url = NULL) {
if($url==NULL) return false;
$protocol = '(http://|https://)';
$allowed = '([a-z0-9]([-a-z0-9]*[a-z0-9]+)?)';
$regex = "^". $protocol . // must include the protocol
'(' . $allowed . '{1,63}\.)+'. // 1 or several sub domains with a max of 63 chars
'[a-z]' . '{2,6}'; // followed by a TLD
if(eregi($regex, $url)==true) return true;
else return false;
}
哪位好心人能给我一个替换代码来替换eregi所需的任何东西
【问题讨论】:
-
替换它的目的是什么?
-
@William,从 PHP 5.3 开始,
ereg、eregi、split等函数已被弃用(不仅被弃用,而且被完全删除)。 Read more. -
@William,但是这个解决方案过于本地化了这个特殊情况......如果他将一些代码移植到 PHP 5.3,他需要更通用的解决方案。