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


70

我正在尝试建立一个捐赠中心,使用的是Totorialzine的源代码。

到目前为止,到目前为止一切都对我来说还算不错,但是我一直在苦苦挣扎并试图整天查看的唯一问题,无法确切知道代码的实际错误所在

这是我的访客捐赠时在页面上提交评论时得到的。

Fatal error: Call to undefined function mb_strlen() in /home/yoursn0w/public_html/livetv/premium/thankyou.php on line 14

这是php文件中的代码。

<?php

require "config.php";
require "connect.php";

if(isset($_POST['submitform']) && isset($_POST['txn_id']))
{
    $_POST['nameField'] = esc($_POST['nameField']);
    $_POST['websiteField'] =  esc($_POST['websiteField']);
    $_POST['messageField'] = esc($_POST['messageField']);

    $error = array();

    if(mb_strlen($_POST['nameField'],"utf-8")<2)
    {
        $error[] = 'Please fill in a valid name.';
    }

    if(mb_strlen($_POST['messageField'],"utf-8")<2)
    {
        $error[] = 'Please fill in a longer message.';
    }

    if(!validateURL($_POST['websiteField']))
    {
        $error[] = 'The URL you entered is invalid.';
    }

    $errorString = '';
    if(count($error))
    {
        $errorString = join('<br />',$error);
    }
    else
    {
        mysql_query("   INSERT INTO dc_comments (transaction_id, name, url, message)
                        VALUES (
                            '".esc($_POST['txn_id'])."',
                            '".$_POST['nameField']."',
                            '".$_POST['websiteField']."',
                            '".$_POST['messageField']."'
                        )");

        if(mysql_affected_rows($link)==1)
        {
            $messageString = '<a href="donate.php">You were added to our donor list! &raquo;</a>';
        }
    }
}

?>

我的phpMyAdmin数据库已经上传完成

这是我按照安装说明进行操作的地方

http://tutorialzine.com/2010/05/donation-center-php-mysql-paypal-api/


2
php.net/manual/en/mbstring.installation.php-您需要启用或安装mbstring PHP扩展才能使用该功能。
hakre 2011年

Answers:


84

mb_strlen()默认情况下,PHP中未启用该功能。请阅读手册以获取安装详细信息:

http://www.php.net/manual/zh/mbstring.installation.php


1
mbstring.detect_order mbstring.encoding_translation mbstring.func_overload mbstring.http_input mbstring.http_output mbstring.internal_encoding mbstring.language mbstring.substitute_character这里是我发现的,如果您可以将我指向右边,它将定义与我必须启用的功能相同的东西。一?
阿里

2
@Ali-许多系统都具有php.ini文件的多个实例,这可能使您难以相信哪个实例。最好的做法是在您的站点下实现一个简单调用的测试页phpinfo()。在该页面的输出中搜索“ mbstring”模块。如果您在此处看不到它,则未安装它。
AJ。

2
@Ali-通过创建一个仅调用的PHP页面,您不会丢失任何数据phpinfo()。请根据我之前的评论尝试此操作,并查看实际上是否为您的环境安装了mbstring。
AJ。

1
@Ali-两件事:1.我看不到在您的环境中安装mbstring的任何证据。如果有权限,则需要安装它。请参阅我上面提供的文档链接。2.删除测试页面的网址!您的公共主机名在的输出中可见phpinfo()。通过发布公共主机名,您正面临风险。我的意图是帮助您,但其他人可能会有更多恶意的意图。
AJ。

3
@AJ我终于安装了mbstring,现在我的脚本正常工作了!!这就是我所做的,它比我想象的要简单!!!WHM->软件-> EasyApache,然后在步骤5中单击“穷举选项列表”,然后选中Mbstring框,然后继续进行构建过程。这比尝试手动执行要简单得多。
阿里(Ali)

36

要解决此问题,请安装php7.0-mbstring软件包:

sudo apt install php7.0-mbstring

4
这适用于使用apt并具有更新软件包的任何系统,例如Ubuntu 16.06 LTS。sudo systemctl restart apache2使用mbstring函数之前,我需要在运行此命令后重新启动Apache 。
贾斯汀·迈克尔

使用nginx的16.04 LTS上的RedBeanPHP需要此功能
malhal

对我来说:sudo apt install php5.6-mbstring && sudo服务nginx reload
Matiss


6

在Centos,RedHat,Fedora和其他yum-my系统上,它比PHP手册所建议的要简单得多:

yum install php-mbstring
service httpd restart


2

如果Google搜索此错误

Call to undefined function mb_ereg_match()

将某人带到此线程。安装php-mbstring也可以解决该问题。

Ubuntu 18.04.1,PHP 7.2.10

sudo apt-get install php7.2-mbstring

1

PHP 7.2 Ubuntu的18.04

sudo apt install php-mbstring

0

这对我在Debian Stretch上起作用

sudo apt-get update
sudo apt install php-mbstring
service apache2 restart
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.