Yuri
Yuri

Reputation: 3284

call to undefined function mb_strimwidth

Months ago I made a short code that uses mb_strimwidth() to exactly fit some text into a table cell, putting dots at the end of a truncated string. Now, after some times, I tried to execute that same code and it went out with this error:

Fatal error: Call to undefined function mb_strimwidth() in ...

I tried to find the mbstring.php file, and when I found the mb_strimwidth() function, I discovered that it is not implemented anymore. How is that possible? But my main question is: how can I get the same result as mb_strimwidth()? I thought to rewrite the function using a loop and mb_strwidth(), but ALL the functions in that mbstring.php file are empty.

Upvotes: 47

Views: 70549

Answers (7)

Nur Uddin
Nur Uddin

Reputation: 1840

If you are using cPanel, you can try this:

Login to cPanel.
Go to the section 'Software'.
Click the icon 'Select PHP Version'
Select the php extension 'mbstring'.
Click the button 'Save'.

Upvotes: 0

Deyvisson Lopes
Deyvisson Lopes

Reputation: 11

If you've arrived at this solution and have already tried executing:

sudo apt-get install php-mbstring

But it didn't work, consider updating your package lists first by running:

sudo apt-get update

This might seem simple, but it's crucial and could solve your issue.

Upvotes: 1

Nelson Katale
Nelson Katale

Reputation: 1539

This error is mostly caused by a missing package called multibyte string or in short mbstring.

First check which php.ini is currently set;

php -i | grep php.ini

Then check if mbstring is installed;

php -i | grep php-mbstring

If it returns nothing, then install it;

sudo apt install php-mbstring

Or you can install according to the php version installed in your workstation

sudo apt install php8.2-mbstring

Now verify that mbstring is installed;

php -i | grep php-mbstring

It should return some info.

Upvotes: 4

Hyder B.
Hyder B.

Reputation: 12286

Just got this issue, if you are using linux just install the package php-mbstringand restart Apache.

sudo apt-get install php-mbstring
sudo service apache2 restart

If you are using specific PHP version, you may need to run the following:

sudo apt-get install php7.x-mbstring
sudo service apache2 restart

Replace 7.x by the exact PHP version.

Upvotes: 35

Turan Zamanlı
Turan Zamanlı

Reputation: 3926

if you already installed mbstring then you have to call this extension on php.ini file.

First, detect where is your php-fpm.ini file or php.ini.

run command

php -i | grep php.ini

it returns you path of php.ini file.

for example

/etc/php.ini

then open file with VIM or another editor

vim /etc/php.ini

and then add mbstring extension to php.ini file

extension=mbstring.so;

finally, restart php-fpm

systemctl restart php-fpm

Upvotes: 1

Jignesh Joisar
Jignesh Joisar

Reputation: 15175

u need to install php-mbstring package try.

check php version

php -v

then check mbstring already install and enable

php -i | grep mbstring

if not installed run this command

sudo apt-get install php-mbstring

if you are php other version example : 7.1, 7.2, 7.0 based on run command like this :

sudo apt-get install php7.1-mbstring 

if you are using nginx server for run laravel .. then check nginx configration file which version u have loaded in conf file..

go to cd /etc/nginx/sites-available and open your configuration file.. if you are loading php7.2 version in nginx conf file..

fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;

then u need to install 7.2 mbstring package..

sudo apt-get install php7.2-mbstring 

and restart apache2 server

 sudo service apache2 restart

Upvotes: 6

Michel Feldheim
Michel Feldheim

Reputation: 18250

All mb_* functions are provided by a PHP extension called Multibyte String, internal name mbstring

You probably don't have the extension active or installed. On most Linux distros you can install the package php-mbstring to install and activate this extension.

Apache needs to be restarted afterwards if you are using mod_php

Upvotes: 81

Related Questions