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

无法在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 我这个代码哪里有问题 acm 平台上显示错误 90%,我自己运行好像没什么问题
  • ¥50 C#编程中使用printDocument类实现文字排版打印问题
  • ¥15 找会编程的帅哥美女 可以用MATLAB里面的simulink编程,用Keil5编也可以。
  • ¥15 已知隐函数其中一个变量τ的具体值,求另一个变量
  • ¥15 r语言Hurst指数
  • ¥15 Acrn IVSHMEM doorbell问题
  • ¥15 yolov5中的val测试集训练时数量变小问题
  • ¥15 MPLS/VPN实验中MPLS的配置问题
  • ¥15 materialstudio氢键计算问题
  • ¥15 echarts图表制作