Skip to Content

How to enable mbstring in PHP?

Estimated Reading Time: 3 Minutes

It is required to have PHP enabled with mbstring (multi-byte string) support for storing and displaying multi-byte characters in PHPKB software. The installation wizard of the multi-language editions of PHPKB knowledge base software will automatically detect if you have PHP enabled with mbstring support. If it is not enabled, you may get an error that says:

Call to undefined function mb_convert_encoding()

Please refer to the tutorial below on how to enable mbstring on your server.

Why mbstring is required?

When we manipulate (trim, split, splice, etc.) strings encoded in a multi-byte encoding, we need to use special functions since two or more consecutive bytes may represent a single character in such encoding schemes. Otherwise, if we apply a non-multibyte-aware string function to the string, it probably fails to detect the beginning or end of the multibyte character and ends up with a corrupted garbage string that most likely loses its original meaning.

So, mbstring provides multibyte-specific string functions that help us deal with multibyte encodings in PHP. In addition to that, mbstring handles character encoding conversion between the possible encoding pairs. mbstring is designed to handle Unicode-based encodings such as UTF-8 and UCS-2 and many single-byte encodings for convenience.

MBstring Installation

Please note that "mbstring" is a non-default PHP extension. This means it is not enabled by default.

Installation on Linux Server

You can find out if this module is installed or not by looking at the list that is produced by this command

php -m

If you don’t have this installed on a Linux machine and if you have installed PHP from yum then run this command as a superuser. The command depends on your operating system.

sudo yum install php-mbstring
This command is true for all Red Hat Linux-based distributions using RPM and the ’yum’ package manager; this includes RHEL, Fedora, CentOS, Mandriva, and Intrinsic Linux, among others.
For Debian, Ubuntu distributions, please use the following command.

sudo apt-get install php-mbstring

After that, you will need to restart your Apache service using the following command:

service httpd restart

Installation on Windows Server

If you have access to the php.ini, just remove the semicolon character (;) in front of the line below.

extension = php_mbstring.dll

Once you have made the changes, don’t forget to restart your web server for the change to take effect.

Note: PHP extensions are not just enabled from php.ini file. First, you need to install that specific extension, i.e. place its DLL file "php-mbstring.dll" into the "/php/ext/" directory if it is not already present there. When you do that, make sure you have the correct build of DLL file. 32-bit, thread-safe PHP binary, built using VC9 for example, would only work with DLL files built using exact same tools and configuration: 32-bit, using VC9, with thread-safety turned on. And of course PHP API version also needs to match. If it doesn’t, once you restart the web server, you will receive ’Error 500 - Server error’ message.

MBstring Configuration

Below is a sample excerpt from php.ini file which contains the configuration of mbstring variables.

[mbstring]
mbstring.language = all
mbstring.internal_encoding = UTF-8
mbstring.http_input = auto
mbstring.http_output = UTF-8
mbstring.encoding_translation = On
mbstring.detect_order = UTF-8
mbstring.substitute_character = none;
mbstring.func_overload = 0
mbstring.strict_encoding = Off
  • Applicable To: Standard (Multi-Language) Edition, Enterprise Multi-Language Edition (MySQL), Enterprise Multi-Language Edition (SQL Server)
How to enable mbstring in PHP?
  • COMMENT