在Yii2 Framework中调用PHP上的未定义函数yii \ helpers \ mb_strlen()

时间:2018-02-23 03:32:08

标签: php

我尝试在服务器上运行项目时发生错误。

无法在/var/www/html/amhadm/vendor/yiisoft/yii2/helpers/BaseStringHelper.php中定义mb_strlen()

这是我在BaseStringHelper.php中的代码

 public static function basename($path, $suffix = '')
{
    if (($len = mb_strlen($suffix)) > 0 && mb_substr($path, -$len) == $suffix) {
        $path = mb_substr($path, 0, -$len);
    }
    $path = rtrim(str_replace('\\', '/', $path), '/\\');
    if (($pos = mb_strrpos($path, '/')) !== false) {
        return mb_substr($path, $pos + 1);
    }

    return $path;
}

有人可以指导我如何解决这个问题吗?

2 个答案:

答案 0 :(得分:0)

PHP默认情况下未启用mb_strlen()功能。您需要手动安装它。在这里查看详细信息:

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

答案 1 :(得分:0)

安装mbstring 对于5.6版

#include <iostream> #include<string> #include <bits/stdc++.h> using namespace std; class ZambiaStudents { private: // Private attribute string FNames; string Sex; string NRC; int birthYear; public: //constructor ZambiaStudents(string FNames, string Gender, string NRC, int birthYear) { this->FNames = FNames; this->Sex = Sex; this->NRC = NRC; this->birthYear = birthYear; } public: // Setters void setFNames(string FNames) { this->FNames = FNames; } void setGender(string FNames) { this->Sex = Sex; } void setNRC(string FullNames) { this->NRC = NRC; } void setbirthYear(int birthYear) { this->birthYear = birthYear; } // Getters string getFNames() { return FNames; } string getSex() { return Sex; } string getNRC() { return NRC; } int getbirthYear() { return birthYear; } public: int calcAge() { int age; age=2020-getbirthYear(); return age; } }; class RusanguStudents: public ZambiaStudents { private: string ID; //student id string AcNo; //account number int NumOfCourses; // number of courses public: RusanguStudents(string ID, string AcNo, int NumOfCourses, string FNames, string Sex, string NRC, int birthYear) : ZambiaStudents(FNames, Sex, NRC, birthYear) { this->AcNo; this->ID; this->NumOfCourses; } public: // Setters void setID(string ID) { this->ID = ID; } void setAcNo(string AcNo) { this->AcNo = AcNo; } void setNumOfCourses(int NumOfCourses) { this->NumOfCourses = NumOfCourses; } // Getters string getID() { return ID; } string getAcNo() { return AcNo; } int getNumOfCourses() { return NumOfCourses; } public: int calcBill() { int bill=500 * getNumOfCourses(); return bill; } }; class ArrayOfRusanguStudents : public RusanguStudents{ public: //student names and age arrays string stnames[5]; int stage[5]; public: //Constructor ArrayOfRusanguStudents(string AcNo, string ID, int NumOfCourses, string FNames, string Sex, string NRC, int birthYear) : RusanguStudents(AcNo, ID, NumOfCourses, FNames, Sex,NRC, birthYear){ } void assignStudentNames() { for (int x = 0; x < (sizeof(stnames) / sizeof(stnames[0])); x++) { cout << ("Enter fullname for Student ") << (x << 0) << (": ") << endl; string names; getline(cin, names); this->setFNames(names); stnames[x] = this->getFNames(); } } void assignStudentage() { for (int x = 0; x < (sizeof(stage) / sizeof(stage[0])); x++) { //request user input cout << ("Enter Year of birth for ") << stnames[x] << endl; int year; cin >> year; this->setbirthYear(year); //calculate age int age = this->calcAge(); //append age to array of student age stage[x] = age; } } void sortStnames(){ int N = sizeof(stnames)/sizeof(stnames[0]); //Get the array size sort(stnames,stnames+N); //Use the start and end like this for(int i = 0; i < N; i++){ cout << stnames[i] <<endl; } } //student age sorting method void sortStage() { int n = sizeof(stage)/sizeof(stage[0]); sort(stage, stage+n); cout << "The Rusangu Student names are ordered according to age: \n"; for (int i = 0; i < n; ++i){ cout << stnames [i] << " is: " << stage[i] << " years old" << endl; } } }; int main() { ArrayOfRusanguStudents ComputerRusanguStudents("I8829", "A34", 5, "Jane Doe", "Female", "220011/23/1", 1998); ComputerRusanguStudents.assignStudentNames(); cout << "The following is list of Students sorted by name: \n" ; ComputerRusanguStudents.sortStnames(); ComputerRusanguStudents.assignStudentage(); cout << "The following is list of Students sorted by age: \n" ; ComputerRusanguStudents.sortStage(); return 0; }

对于php 7.0 sudo apt install php5.6-mbstring