user2431224
user2431224

Reputation: 235

Call to undefined function yii\helpers\mb_strlen() even though mbstring is enabled

I have enabled mbstring in my php.ini.It even shows in phpinfo().But still I am getting this error in yii2.

PHP Fatal Error 'yii\base\ErrorException' with message 'Call to undefined function yii\helpers\mb_strlen()

Upvotes: 0

Views: 3086

Answers (1)

arogachev
arogachev

Reputation: 33548

As @TomaszKane said in comment, mb_strlen() is native PHP function, so you need to call it as mbstrlen() without specifying the namespace.

Official documentation:

Also take a look at yii\helpers\StringHelper, mb_strlen() is used in several places. For example, if you are looking for byte length, there is special method byteLength(), you can call it like that:

use yii\helpers\StringHelper;

...

StringHelper::byteLength($string);

It's basically syntactic sugar of mb_strlen().

Upvotes: 1

Related Questions