php 致命错误:调用未定义的函数 mb_substr()

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14035698/
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-08-25 06:28:24  来源:igfitidea点击:

Fatal error: Call to undefined function mb_substr()

phpstring

提问by Blahwhore

I wanted to see your input on this concern I'm currently experiencing. It turns out that:

我想看看你对我目前遇到的这个问题的意见。事实证明:

 <?php
$disc_t=$name; 
  if(strlen($disc_t)<=15)
  {
   $name_now=mb_substr( strip_tags($disc_t), 0, 10 ).'';
  }
  else
  {
   $name_now=mb_substr( strip_tags($disc_t), 0, 10).'...';
  }
?>

is somehow giving me an error on the site, the error shows:

不知何故在网站上给我一个错误,错误显示:

Fatal error: Call to undefined function mb_substr() in /home/(website)/public_html/index.php on line 308

I don't quite understand what they mean by mb_substr, is this a PHP version error? I am currently using PHP 5.3.19

我不太明白他们的意思mb_substr,这是PHP版本错误吗?我目前使用的是 PHP 5.3.19

回答by Niet the Dark Absol

mb_substr()is a multibyte-safe version of substr(), meaning it works with charactersas opposed to bytes. This is most noticeable in UTF-8, where many characters are represented by two or more bytes.

mb_substr()是 的多字节安全版本substr(),这意味着它适用于字符而不是字节。这在 UTF-8 中最为明显,其中许多字符由两个或更多字节表示。

According to the installation instructions, mbstringis not a built-in extension. You must enable it by having the appropriate files and configuring PHP correctly. Some information can be found in the link provided, your webhost should be able to help you with the rest.

根据安装说明mbstring不是内置扩展。您必须通过拥有适当的文件并正确配置 PHP 来启用它。可以在提供的链接中找到一些信息,您的虚拟主机应该能够帮助您完成其余的工作。

To see if mbstring is installed: php -m | grep mbstring

要查看是否安装了 mbstring: php -m | grep mbstring

For Linux, install using

对于 Linux,安装使用

sudo apt-get install php-mbstring

sudo apt-get install php-mbstring

回答by Sverri M. Olsen

Throw this into a terminal:

把它扔进一个终端:

php -m | grep mb

If mbstringshows up then it should work.

如果mbstring出现,那么它应该可以工作。

回答by Pt. Raman Sharma

If you have root access, you can configure it using WHM Panel or using Command Line. I will let you know how you can do it using WHM Panel.
1. Login to your WHM with Root User
2. Go to Easyapache
3. Go to previously saved configuration
4. Click on Start Customizing based on Profile.
5. Don't change apache and php version, just click next.
6. Click on Exhaustive options list at the bottom of php configuration
7. Select the checkbox near MBString option
8. Save and Build
9. Do not close your browser window if it takes a while. Be patient.
You are Done!!!

如果您具有 root 访问权限,则可以使用 WHM 面板或使用命令行对其进行配置。我会告诉你如何使用 WHM 面板来做到这一点。
1. 使用 Root 用户登录您的 WHM
2. 进入 Easyapache
3. 进入之前保存的配置
4. 点击 Start Customizing based on Profile。
5.不要更改apache和php版本,直接点下一步。
6. 单击 php 配置底部的 Exhaustive 选项列表
7. 选中 MBString 选项附近的复选框
8. 保存并构建
9. 如果需要一段时间,请不要关闭浏览器窗口。要有耐心。
你完成了!!!

回答by root

The error is telling you that you are trying to use a function named mb_substr that doesn't exist.

该错误告诉您,您正在尝试使用不存在的名为 mb_substr 的函数。

Perhaps you can achieve the same result using the substr function http://php.net/manual/en/function.substr.phpinstead. substr(strip_tags($disc_t), 0, 10) will return the first ten characters of the result of strip_tags($disc_t) .

也许您可以使用 substr 函数http://php.net/manual/en/function.substr.php来实现相同的结果。substr(strip_tags($disc_t), 0, 10) 将返回 strip_tags($disc_t) 结果的前十个字符。