记录日常点点滴滴,欢迎来到我的小站。

0%

WordPress 提示Fatal error: Call to undefined function mb_strimwidth()

WordPress 提示Fatal error: Call to undefined function mb_strimwidth() in category.php on line 27,原因PHP没有启用mb_strimwidth函数,

解决方法如下:
打开php.ini,找到;

1
extension=php_mbstring.dll,

去掉前面的分号保存,重启IIS或PHP即可。
如果上面方法不能解决可参考
在谷歌了一阵后终于找到了一个完美的解决方案。
本来没有mb_strimwidth函数打开wordpress首页时是肯定会出现
Fatal error: Call to undefined function: mb_strimwidth() 错误在index.php第17行
这样的提示的,然后打开正在使用的wordpress模板的index.php后第17行会发现如下一段

1
2
<?php
echo dm_strimwidth(strip_tags(apply_filters('the_content', $post->post_content)), 0, 290,"..."); ?>

将其更改为:

1
2
3
<?php
echo ok_strimwidth(strip_tags(apply_filters('the_content', $post->post_content)), 0, 290,"...");
?>

么 ok_strimwidth这个函数在这里是调用了,可是存在哪呢?别着急,打开wordpress的 wp-includes目录会有一个functions.php,
在里面增加如下代码

1
2
3
4
functionok_strimwidth($str ,$start , $width ,$trimmarker ){
$output = preg_replace('/^(?:[x00-x7F]|[xC0-xFF][x80-xBF]+){0,'.$start.'}((?:[x00-x7F]|[xC0-xFF][x80-xBF]+){0,'.$width.'}).*/s','1',$str);
return $output.$trimmarker;
}

这样就定义了 ok_strimwidth函数,现在打开你的首页看看是不是正常了?