laravel 调用未定义的函数 mb_strimwidth

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14254943/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 07:28:40  来源:igfitidea点击:

call to undefined function mb_strimwidth

phpstringlaraveltruncationmbstring

提问by Yuri

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:

几个月前,我编写了一个短代码,用于mb_strimwidth()将一些文本精确地放入表格单元格中,在截断字符串的末尾放置点。现在,一段时间后,我尝试执行相同的代码,结果出现以下错误:

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.

我试图找到mbstring.php文件,当我找到该mb_strimwidth()函数时,我发现它不再实现了。这怎么可能?但我的主要问题是:我怎样才能得到与mb_strimwidth()? 我想使用循环和重写函数mb_strwidth(),但该 mbstring.php 文件中的所有函数都是空的。

回答by Michel Feldheim

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

所有mb_*函数均由名为 Multibyte String 的 PHP 扩展提供,内部名称为mbstring

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

您可能没有激活或安装扩展。在大多数 Linux 发行版上,您可以安装该软件包php-mbstring来安装和激活此扩展。

Apache needs to be restarted afterwards if you are using mod_php

如果您使用的是 mod_php,则需要在之后重新启动 Apache

回答by Hyder B.

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

刚刚遇到这个问题,如果您使用的是 linux,只需安装软件包php-mbstring并重新启动 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:

如果您使用特定的 PHP 版本,则可能需要运行以下命令:

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

Replace 7.xby the exact PHP version.

替换7.x为确切的 PHP 版本。

回答by Jignesh Joisar

u need to install php-mbstringpackage try.

你需要安装php-mbstring包试试。

check php version

检查 php 版本

php -v

then check mbstring already install and enable

然后检查 mbstring 已经安装并启用

php -i | grep mbstring

if not installed run this command

如果未安装,请运行此命令

sudo apt-get install php-mbstring

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

如果您是php 其他版本示例:7.1、7.2、7.0基于这样的运行命令:

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..

如果您使用 nginx 服务器运行 laravel .. 然后检查 nginx 配置文件您在 conf 文件中加载了哪个版本..

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

cd /etc/nginx/sites-available打开你的配置文件..如果你在nginx conf文件中加载php7.2版本..

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

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

then u need to install 7.2mbstring package..

然后你需要安装7.2mbstring 包..

sudo apt-get install php7.2-mbstring 

and restartapache2 server

重新启动apache2 服务器

 sudo service apache2 restart

回答by Turan Zamanl?

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

如果你已经安装了 mbstring 那么你必须在 php.ini 文件上调用这个扩展。

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

首先,检测您的 php-fpm.ini 文件或 php.ini 在哪里。

run command

运行命令

php -i | grep php.ini

it returns you path of php.ini file.

它返回 php.ini 文件的路径。

for example

例如

/etc/php.ini

then open file with VIM or another editor

然后用 VIM 或其他编辑器打开文件

vim /etc/php.ini

and then add mbstring extension to php.ini file

然后将 mbstring 扩展名添加到 php.ini 文件

extension=mbstring.so;

finally, restart php-fpm

最后,重启 php-fpm

systemctl restart php-fpm