我在 php.ini 中启用了 mbstring。它甚至显示在 phpinfo() 中。但我仍然在 yii2 中收到此错误。
PHP Fatal Error 'yii\base\ErrorException' with message 'Call to undefined function yii\helpers\mb_strlen()
正如@TomaszKane 在评论中所说,mb_strlen()
是原生 PHP 函数,所以你需要在mbstrlen()
不指定命名空间的情况下调用它。
官方文档:
还要看看yii\helpers\StringHelper,mb_strlen()
它在几个地方都有使用。例如,如果你正在寻找字节长度,有一个特殊的方法byteLength(),你可以这样调用它:
use yii\helpers\StringHelper;
...
StringHelper::byteLength($string);
它基本上是mb_strlen()
.