How can I check if the mbstring extension is loaded in a php script?
Asked
Active
Viewed 4.3k times
7 Answers
42
Use if (extension_loaded('mbstring')) { /* loaded */ }
See PHP manual.

Maxime Pacary
- 22,336
- 11
- 85
- 113
16
Also useful:
php -i | grep mbstring
Output:
/etc/php/8.1/cli/conf.d/20-mbstring.ini,
Zend Multibyte Support => provided by mbstring
Multibyte decoding support using mbstring => enabled
mbstring
mbstring extension makes use of "streamable kanji code filter and converter", which is distributed under the GNU Lesser General Public License version 2.1.
mbstring.detect_order => no value => no value
mbstring.encoding_translation => Off => Off
mbstring.http_input => no value => no value
mbstring.http_output => no value => no value
mbstring.http_output_conv_mimetypes => ^(text/|application/xhtml\+xml) => ^(text/|application/xhtml\+xml)
mbstring.internal_encoding => no value => no value
mbstring.language => neutral => neutral
mbstring.regex_retry_limit => 1000000 => 1000000
mbstring.regex_stack_limit => 100000 => 100000
mbstring.strict_detection => Off => Off
mbstring.substitute_character => no value => no value

matinict
- 2,411
- 2
- 26
- 35

Geoffrey Hale
- 10,597
- 5
- 44
- 45
16
From terminal/console, go in PHP CLI mode and echo the command as below,
$ php -a
php > echo extension_loaded('mbstring');
1
It will return 1 if mbstring is loaded as an extension otherwise null

UserBSS1
- 2,091
- 1
- 28
- 31
14
Run this code in php file --
<?php phpinfo(); ?>

swapnesh
- 26,318
- 22
- 94
- 126
-
You forgot mention which parameter it is,. – Fernando Torres Sep 05 '19 at 22:31
1
You can check it through phpinfo().
Search for the string "mbstring" in phpinfo page. If it is present means then mbstring is enabled or it is disabled.

Rajasekar PHP
- 611
- 2
- 9
- 16
0
if you cannot find mbstring in phpinfo();
change extension_dir = "ext" to extension_dir = "c:/php/ext"
in c:\php\php.ini file

Rohollah
- 1