mb_convert_encoding, undefined function while mbstring is enabled
Asked Answered
R

4

33

I have a server (Ubuntu 11.10 x64) running PHP 5.3.8 with Apache2 / MySQL. I'm currently working on a project where I'm required to do some specific character encoding, but I found out that none of the multibyte (mb_* functions) are working.

However, when I look in phpinfo(), I see that multibyte support is enabled.

I've tried things like apt-get install php5-mbstring, php-mbstring, php-multibyte, etc. etc. but none seem to work.

Can anyone point me in the right direction for this? Thanks in advance!

edit: Fixed it by recompiling PHP (this was my last resort, which I initially wanted to avoid)

./configure --enable-mbstring

The weird this is, phpinfo() already showed that it was enabled. I don't know why it didn't work before :/

Ringnecked answered 25/11, 2011 at 8:29 Comment(8)
what is the error message when you try any of the mb_* functions?Sergu
Web server configuration vs. CLI configuration? Where exactly do you see what?Canoodle
Do you have libmbfl installed? If so - it should be shown in phpinfo() output as "Multibyte string engine" under mbstring.Convict
Yeah I have that installed. However, I just noticed that the "Zend Multibyte Support" is disabled. Is there a way to enable this without having to recompile PHP?Ringnecked
I don't think it has something to do with the mbstring extension.Convict
@EmirAkaydın - call to undefined function mb_substr or mb_convert_encoding.Ringnecked
now delete your question and get the Disciplined badge ;)Sergu
You solved my problem with your solution, so thanks a lot for that! :)Hundredfold
C
49

A lot of newer Linux servers do not have PHP Multibyte modules installed by default. A simple solution is often to install php-mbstring.

On Red Hat flavors (CentOS, Fedora, etc.) you can use yum install php-mbstring.

Make sure you restart your Apache server afterwards. Use service httpd restart on RH flavors.

Conjunct answered 1/11, 2013 at 13:46 Comment(3)
sudo apt-get install php7.0-mbstring and then sudo service php7.0-fpm restart did the trick for me. Thanks!Plenipotentiary
I had additionally edit the /etc/php/7.0/mods_available/mbstring.ini and remove the ; for the extension line. Suddently it started working for me :)Attenuation
After installation need to run sudo service apache2 restart.Tippett
U
8

In the case of your installation is php5.6 is similar to solution of neilsimp1:

Running sudo apt-get install php7.0-mbstring and then sudo service php7.0-fpm restart did the trick for me.

sudo apt-get install php5.6-mbstring

and then restart apache service

sudo service apache2 restart.
Unrestrained answered 27/8, 2018 at 20:17 Comment(0)
I
2

Sometimes people receiving this kind of error : Fatal error: Call to undefined function mb_convert_encoding() in /public_html/this/this.php at line 188. Normally this kind of errors comes in PHP Sites and PHP framework aswell.

It looks like PHP mbstring not installed on your server.

Solution :

In my case I have just uncomment ;extension=php_mbstring.dll in php.ini file and issue has been resolved.

Don't forget to restart apache server after uncomment ;extension=php_mbstring.dll

Code taken from this blog: http://chandreshrana.blogspot.in/2016/01/call-to-undefined-function.html

Indusium answered 2/7, 2016 at 6:6 Comment(1)
This was the working solution for me (using windows, IIS, php 7.4). Don't forget to restart IIS.Transmit
W
0

Check if MBString is Installed

You can know if it is actually installed or not with the -m (Show compiled in modules) arg...

php -m | grep mbstring

If installed, you will see mbstring as the output from the above, or blank if it is not installed.

Install MBString

If you have the newest PHP (PHP8 right now), you can install with...

apt-get install php-mbstring 
yum install php-mbstring

If you have PHP7, and you need an older MBString, then install with...

apt-get install php7.0-mbstring
yum install php7.0-mbstring

Restart the Server

Restart the server after install with this at your command line:

/etc/init.d/apache2 restart

Refer back to step 1 to check that MBString actually installed.

Welborn answered 29/12, 2021 at 18:33 Comment(2)
This is very system specific, and not very widely applicable; where does php70w-mbstring come from? Most people do not run PHP as an Apache module any longer, and if they do there's a good chance the old sysv init scripts aren't available; most systems use systemd now.Auvil
Oops, that was actually a copy/paste error, thanks for catching, I meant to have php7.0-mbstring there.Welborn

© 2022 - 2024 — McMap. All rights reserved.