douzhuochao4027 2019-07-28 20:44
浏览 166


I need to use mb_strlen to sort an array of words with diacritics, but PHP does not recognize this function, although mb_string is installed.

So, if I say

function sortByStrlen($a, $b)
  if (mb_strlen($a, "utf-8") === mb_strlen($b, "utf-8")) {
    return $a > $b;
  } else {
    return mb_strlen($b, "utf-8") - mb_strlen($a, "utf-8");

#sort my array
usort($myArray, 'sortByStrlen');

Won't work on my Ubuntu virtual machine that is running on the server, although it was working on my Windows local machine,

I've spent over 2,5 hours searching this issue and I've tried many solutions, both here in StackOverflow and in AskUbuntu.

These solutions did not work for me:

PHP: Call to undefined function mb_strlen() - on custom compiled PHP with mbstring enabled

Fatal error: Call to undefined function mb_strlen()

Call to undefined function yii\helpers\mb_strlen() on PHP in Yii2 Framework

This is just to name a few! I did a deep search, but I did not find what I need. Please, do not mark it as duplicate because I really need help (indeed, this problem is making me tired).

I already installed mb_string through the terminal:

sudo apt-get install php7.3-mbstring

I'm sure the mbstring module is compatible with my PHP version. Then, I uncommented the lines in php.ini to activate the mbstring module


I also uncommented extensions:

extension_dir = "./"

I restarted the server:

 sudo /etc/init.d/apache2 restart

I also see other modules, like mysql, when I use php-m.

When I run phpinfo, I can see that the mbstring is on the list of the modules being loaded.

If I run php -m on the terminal, it will give me a list of modules and mbstring is there.

HOWEVER, if I run:



It will ouput:


Yet, after all of this, I restarted Apache and MySQL many times. So I can't see why mbstring is not being enabled!

As explained at the beginning of this post, I need to sort words with diacritics by their length. So, if you have another solution for this, I will accept it.

I'm not getting error messages because this is for production. The code is running on my personal website in a virtual machine; because it is production, PHP does not show errors by default and I don't know how to enable them.

Notes: Ubuntu version is 18.04 PHP version is 7.3


As requested by @gview, if I run dpkg -l | grep php, I get:

ii  libapache2-mod-php7.3                      amd64        server-side, HTML-embedded scripting language (Apache 2 module)
ii  php-common                             all          Common files for PHP packages
ii  php-gettext                     1.0.12-0.1                                               all          transitional dummy package for php-php-gettext
ii  php-mbstring                       all          MBSTRING module for PHP [default]
ii  php-pear               all          PEAR Base System
ii  php-php-gettext                 1.0.12-0.1                                               all          read gettext MO files directly, without requiring anything other than PHP
ii  php-xml                            all          DOM, SimpleXML, WDDX, XML, and XSL module for PHP [default]
ii  php7.3                                     all          server-side, HTML-embedded scripting language (metapackage)
ii  php7.3-cli                                 amd64        command-line interpreter for the PHP scripting language
ii  php7.3-common                              amd64        documentation, examples and common module for PHP
ii  php7.3-json                                amd64        JSON module for PHP
ii  php7.3-mbstring                            amd64        MBSTRING module for PHP
ii  php7.3-mysql                               amd64        MySQL module for PHP
ii  php7.3-opcache                             amd64        Zend OpCache module for PHP
ii  php7.3-readline                            amd64        readline module for PHP
ii  php7.3-xml                                 amd64        DOM, SimpleXML, WDDX, XML, and XSL module for PHP

That may help you help me.

  • 写回答

1条回答 默认 最新



  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序