douzhuochao4027 2019-07-28 20:44
浏览 166
已采纳

无法在PHP中启用mb_string

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

https://askubuntu.com/questions/772397/mbstring-is-missing-for-phpmyadmin-in-ubuntu-16-04

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

;extension=mbstring

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:

<?php

var_dump(extension_loaded('mbstring'));

It will ouput:

bool(false)

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

UPDATE 2

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

ii  libapache2-mod-php7.3           7.3.7-2+ubuntu18.04.1+deb.sury.org+1                     amd64        server-side, HTML-embedded scripting language (Apache 2 module)
ii  php-common                      2:69+ubuntu18.04.1+deb.sury.org+2+php7.3                 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                    2:7.3+69+ubuntu18.04.1+deb.sury.org+2+php7.3             all          MBSTRING module for PHP [default]
ii  php-pear                        1:1.10.8+submodules+notgz-1+ubuntu18.04.1+deb.sury.org+1 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                         2:7.3+69+ubuntu18.04.1+deb.sury.org+2+php7.3             all          DOM, SimpleXML, WDDX, XML, and XSL module for PHP [default]
ii  php7.3                          7.3.7-2+ubuntu18.04.1+deb.sury.org+1                     all          server-side, HTML-embedded scripting language (metapackage)
ii  php7.3-cli                      7.3.7-2+ubuntu18.04.1+deb.sury.org+1                     amd64        command-line interpreter for the PHP scripting language
ii  php7.3-common                   7.3.7-2+ubuntu18.04.1+deb.sury.org+1                     amd64        documentation, examples and common module for PHP
ii  php7.3-json                     7.3.7-2+ubuntu18.04.1+deb.sury.org+1                     amd64        JSON module for PHP
ii  php7.3-mbstring                 7.3.7-2+ubuntu18.04.1+deb.sury.org+1                     amd64        MBSTRING module for PHP
ii  php7.3-mysql                    7.3.7-2+ubuntu18.04.1+deb.sury.org+1                     amd64        MySQL module for PHP
ii  php7.3-opcache                  7.3.7-2+ubuntu18.04.1+deb.sury.org+1                     amd64        Zend OpCache module for PHP
ii  php7.3-readline                 7.3.7-2+ubuntu18.04.1+deb.sury.org+1                     amd64        readline module for PHP
ii  php7.3-xml                      7.3.7-2+ubuntu18.04.1+deb.sury.org+1                     amd64        DOM, SimpleXML, WDDX, XML, and XSL module for PHP

That may help you help me.

  • 写回答

1条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果