PHP 7.x preg_replace替换了ereg_replace,D8主题崩坏

来源:转载


文章作者:姜南(Slyar)
文章来源:Slyar Home (www.slyar.com) 转载请注明,谢谢合作。


说什么好呢,一个付费主题bug这么多,作者也不修改。PHP升级到7.x版本以后主题就崩溃了,看了一眼error log真是鲜血淋漓


2017/11/01 04:46:39 [error] 14987#0: *38 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught Error: Call to undefined function ereg_replace() in /不给看/wp-content/themes/d8/header.php:69


ereg_replace: This function was DEPRECATED in PHP 5.3.0, and REMOVED in PHP 7.0.0. (传送门
)


ereg_replace() 的问题,这个东西在PHP 7.x以后就不存在了。匹配语法也从ereg syntax (POSIX)改成了preg syntax (PCRE)。修复方法也很简单,把所有的ereg_replace()和对应的匹配表达式都换成preg_replace()标准就好了


[[email protected] d8]# grep -nr "ereg_replace(/"<div/[^>/]/*><ul/[^>/]/*>/"" ./
./pages/tags.php:11: <?php echo str_replace("</ul></div>", "", ereg_replace("<div[^>]*><ul[^>]*>", "", wp_nav_menu(array('theme_location' => 'pagemenu', 'echo' => false)) )); ?>
./pages/readers.php:22: <?php echo str_replace("</ul></div>", "", ereg_replace("<div[^>]*><ul[^>]*>", "", wp_nav_menu(array('theme_location' => 'pagemenu', 'echo' => false)) )); ?>
./pages/tougao.php:11: <?php echo str_replace("</ul></div>", "", ereg_replace("<div[^>]*><ul[^>]*>", "", wp_nav_menu(array('theme_location' => 'pagemenu', 'echo' => false)) )); ?>
./pages/page.php:12: <?php echo str_replace("</ul></div>", "", ereg_replace("<div[^>]*><ul[^>]*>", "", wp_nav_menu(array('theme_location' => 'pagemenu', 'echo' => false)) )); ?>
./pages/archives.php:11: <?php echo str_replace("</ul></div>", "", ereg_replace("<div[^>]*><ul[^>]*>", "", wp_nav_menu(array('theme_location' => 'pagemenu', 'echo' => false)) )); ?>
./pages/links.php:11: <?php echo str_replace("</ul></div>", "", ereg_replace("<div[^>]*><ul[^>]*>", "", wp_nav_menu(array('theme_location' => 'pagemenu', 'echo' => false)) )); ?>
./header.php:69: <?php echo str_replace("</ul></div>", "", ereg_replace("<div[^>]*><ul[^>]*>", "", wp_nav_menu(array('theme_location' => 'nav', 'echo' => false)) )); ?>

作者我真是。。。服了你了,你写个函数重复用会死么!会!死!么!


请把所有的


ereg_replace("<div[^>]*><ul[^>]*>"

都替换成


preg_replace("/<div[^>]*><ul[^>]*>/"

就好了。。。


(sed表达式太复杂我就不写了,只有7、8个手工改了就行了,要是有几十个那得是脚本改,醉了...)


分享给朋友:
您可能感兴趣的文章:
随机阅读:
栏目列表
推荐内容