• 欢迎访问magento4you博客,我们提供magento建站、技术咨询、IT运维、支持培训、二次开发服务及模板定制,联系QQ:283475615
  • Magento入门教程 二次开发 模板定制 联系QQ:283475615
  • magento运营 SEO SEM 数字营销 广告竞价 联系QQ:283475615
  • 如果您觉得本站对你有帮助,那么赶紧使用Ctrl+D 收藏吧!

PHP 升级到 PHP7出现的问题 Fatal error: Uncaught Error: Call to undefined function ereg_replace()

PHP magento4you 4年前 (2017-06-19) 5386次浏览 0个评论

PHP升级到 PHP7出现了 Fatal error: Uncaught Error: Call to undefined function ereg_replace() 错误,解决方法:php使用preg_replace()代替ereg_replace()。具体做法如下:

1.把php版本更换至php5.0,继续使用早期版本的php环境,但这种方法未免有点不客观,假如你是购买的虚拟主机,你就没有办法更换php版本

2.修改php环境的配置文件,也就是修改php.ini文件:

<span class="pun">找到</span> <span class="pun">;</span><span class="pln">extension</span><span class="pun">=</span><span class="pln">php_mbstring</span><span class="pun">.</span><span class="pln">dll </span><span class="pun">更改为:</span><span class="pln">extension</span><span class="pun">=</span><span class="pln">php_mbstring</span><span class="pun">.</span><span class="pln">dll
</span><span class="pun">找到</span> <span class="pun">;</span><span class="pln">mbstring</span><span class="pun">.</span><span class="pln">func_overload </span><span class="pun">=</span> <span class="lit">0</span> <span class="pun">修改为:</span><span class="pln">mbstring</span><span class="pun">.</span><span class="pln">func_overload </span><span class="pun">=</span> <span class="lit">7</span>

这样也可以继续使用,但修改php.ini文件同第一种方法一样有限制,并不是所有的php运行环境你都有权修改

3.使用最新的正则函数 preg_replace,在正则替换时稍有不同,

如:

<span class="pln">ereg_replace</span><span class="pun">(</span><span class="str">"[/\]{1,}"</span><span class="pun">,</span> <span class="str">'/'</span><span class="pun">,</span><span class="pln"> dirname</span><span class="pun">(</span><span class="pln">__FILE__</span><span class="pun">)</span> <span class="pun">)</span>

修改后应该为:

<span class="pln">preg_replace</span><span class="pun">(</span><span class="str">"/[/\]{1,}/"</span><span class="pun">,</span> <span class="str">'/'</span><span class="pun">,</span><span class="pln"> dirname</span><span class="pun">(</span><span class="pln">__FILE__</span><span class="pun">)</span> <span class="pun">)</span>

在本站(程序员的资料库)中原来的代码

<span class="pun"><?</span><span class="pln">php echo str_replace</span><span class="pun">(</span><span class="str">"</ul></div>"</span><span class="pun">,</span> <span class="str">""</span><span class="pun">,</span><span class="pln"> ereg_replace</span><span class="pun">(</span><span class="str">"<div[^>]*><ul[^>]*>"</span><span class="pun">,</span> <span class="str">""</span><span class="pun">,</span><span class="pln"> wp_nav_menu</span><span class="pun">(</span><span class="pln">array</span><span class="pun">(</span><span class="str">'theme_location'</span> <span class="pun">=></span> <span class="str">'mbt-mainmenu'</span><span class="pun">,</span> <span class="str">'echo'</span> <span class="pun">=></span> <span class="kwd">false</span><span class="pun">))</span> <span class="pun">));</span> <span class="pun">?></span>

修改后

<span class="pun"><?</span><span class="pln">php echo str_replace</span><span class="pun">(</span><span class="str">"</ul></div>"</span><span class="pun">,</span> <span class="str">""</span><span class="pun">,</span><span class="pln"> preg_replace</span><span class="pun">(</span><span class="str">"{<div[^>]*><ul[^>]*>}"</span><span class="pun">,</span> <span class="str">""</span><span class="pun">,</span><span class="pln"> wp_nav_menu</span><span class="pun">(</span><span class="pln">array</span><span class="pun">(</span><span class="str">'theme_location'</span> <span class="pun">=></span> <span class="str">'mbt-mainmenu'</span><span class="pun">,</span> <span class="str">'echo'</span> <span class="pun">=></span> <span class="kwd">false</span><span class="pun">))</span> <span class="pun">));</span> <span class="pun">?></span>
将ereg_replace()替换为preg_replace();
但是这样还是会继续报错,还需要将上方div添加{}或者/转义符号。

极客公园 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:PHP 升级到 PHP7出现的问题 Fatal error: Uncaught Error: Call to undefined function ereg_replace()
喜欢 (2)
发表我的评论
取消评论

*

code

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址