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

Ali*_*Ali 60 php mysql database

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

到目前为止,这一切对我来说都很好,但是我唯一的问题是努力工作并试图查看一整天并且无法确切地知道代码究竟是什么问题

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

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

这是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>';
        }
    }
}

?>
Run Code Online (Sandbox Code Playgroud)

我在phpMyAdmin上传完成了我的数据库

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

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

AJ.*_*AJ. 72

mb_strlen()PHP中默认不启用该功能.请阅读手册了解安装细节:

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

  • @Ali - 许多系统都有 php.ini 文件的多个实例,并且可能会混淆要信任哪一个。最好的做法是在您的站点下实现一个测试页面,该页面只需调用`phpinfo()`。在该页面的输出中搜索“mbstring”模块。如果您在那里没有看到它,则它没有安装。 (2认同)
  • @Ali - 你不会通过创建一个只调用`phpinfo()`的PHP页面来丢失任何数据.请根据我之前的评论尝试这一点,看看是否为您的环境安装了mbstring. (2认同)
  • @AJ我终于安装了mbstring,现在我的脚本工作了!这是我做的,它比我想象的那么简单!WHM - >软件 - > EasyApache并在步​​骤5中单击Exhaustive Options List并选中Mbstring框并继续构建过程.这比手动执行此操作要简单得多. (2认同)

小智 29

要修复此安装php7.0-mbstring包:

sudo apt install php7.0-mbstring
Run Code Online (Sandbox Code Playgroud)

  • 这适用于任何使用apt并具有更新软件包的系统,例如Ubuntu 16.06 LTS.在使用mbstring函数之前,我需要在使用`sudo systemctl restart apache2`运行它之后重新启动Apache. (3认同)

web*_*ter 8

对我来说,以下命令可以解决问题

sudo apt install php-mbstring
Run Code Online (Sandbox Code Playgroud)


kub*_*zyk 5

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

yum install php-mbstring
service httpd restart
Run Code Online (Sandbox Code Playgroud)


Mon*_*lal 5

对我来说,这适用于Ubuntu 14.04和php5.6:

$ sudo apt-get install php5.6-mbstring
Run Code Online (Sandbox Code Playgroud)


dar*_*enp 5

这个问题看起来与 Unix 上的 PHP 有关。但是,对于任何在 Windows 上遇到 PHP 问题的人,请参阅https://www.php.net/manual/en/install.pecl.windows.php

由于多字节字符串支持是核心 PHP 扩展,因此在 Windows 上只需取消注释以下行php.ini

extension=php_mbstring.dll
Run Code Online (Sandbox Code Playgroud)