Home  >  Article  >  Backend Development  >  php 升级到 5.3+ 后出现的一些异常,如 ereg(); ereg_replace(); 函数报错

php 升级到 5.3+ 后出现的一些异常,如 ereg(); ereg_replace(); 函数报错

WBOY
WBOYOriginal
2016-06-13 12:27:50862browse

php 升级到 5.3+ 后出现的一些错误,如 ereg(); ereg_replace(); 函数报错

在php5.3环境下运行,常常会出现

 Deprecated: Function ereg() is deprecated in...和Deprecated: Function ereg_replace() is deprecated in...这些类型的报错提示。
  其原因在于:php5.3以上的版本不支持ereg()函数,而是使用preg_match()函数;不支持ereg_replace()函数,而使用preg_replace()函数。
  解决方法:将不支持的函数修改为支持的函数即可。
   
      例如
  if(eregi('^('value', $value)
  改为:
  if(preg_match('/value/', $value)
   
  再例如:
  $string = ereg_replace(' value', ' ', trim($string)); 
  改为:
  $string = preg_replace('{ value}', ' ', trim($string)); 
   
解决Deprecated: Assigning the return value of new by reference is deprecated in报错

因为我们现在php是5.3的原因,在php5.3之中可以直接用”=”,而之前因为在本地上测试都是5.3以下的php环境用的是”=&”符号。

在 5.3版本之后已经不允许在程序中使用”=&”符号。如果你的网站出现了Deprecated: Assigning the return value of new by reference is deprecated in 错误,别着急,先定位到出错的文件,查找下是不是在程序中使用了”=&”,发现使用了”=&”符号,去掉‘&’符号之后程序运行 正常。

问题:Deprecated: Function set_magic_quotes_runtime() is deprecated in 
导致这个提示的原因是在PHP5.3后此特性(set_magic_quotes_runtime())已经关闭。
而且在PHP6中已经完全移除此特性。
你可以注释或者删除掉出错的行,或者是在set_magic_quotes_runtime()前面加@符号

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn