Function eregi is deprecated (解决方法)
发布时间:2020-12-13 06:25:27 所属栏目:PHP教程 来源:网络整理
导读:在php升级到php5.3之后后,在使用的过程经常发现有的程序会出现Function eregi() is deprecated 的报错信息。 FONT style="COLOR: #ff0000"是什么原因呢? 这是因为php5.3中不再支持eregi()函数,而使用preg_match()函数替代。 FONT style="COLOR: #ff0000"
在php升级到php5.3之后后,在使用的过程经常发现有的程序会出现Function eregi() is deprecated 的报错信息。 <FONT style="COLOR: #ff0000">是什么原因呢?这是因为php5.3中不再支持eregi()函数,而使用preg_match()函数替代。<FONT style="COLOR: #ff0000">解决的方法是:将eregi()函数替换成preg_match() 函数。<FONT style="COLOR: #0000ff">if(eregi('^test',$file))可以替换为 if(preg_match('/^test/i',$file)) ————- PHP 5.3.0 之後的 regex,希望使用 PCRE 的規格,POSIX Regex 都不建議使用了(統一 Regex,避免規格太多?). 所以下述是不建議使用的 Function (POSIX),與建議替換成的 Function (PCRE) 列表,詳可見: PHP: Differences from POSIX regex POSIX → PCRE ereg_replace() → preg_replace() ereg() → preg_match() eregi_replace() → preg_replace() eregi() → preg_match() split() → preg_split() spliti() → preg_split() sql_regcase() → No equivalent 需要 regex 的 split,可用 preg_split() 代替 不需要 regex,只要要快速分割固定的字串,可用 explode() 代替. (速度會比需要 regex 的快很多) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |