substr() or mb_substr() does not work

爷,独闯天下 提交于 2020-01-05 09:05:15

问题


I am parsing webpage content using file_get_content() and then getting plaintext out of that.

Now I want to catch first 150 characters from that plaintext. Here I worked.

DEMo on codepad: DEMO

$data = file_get_contents($url);
$content = plaintext($data); //dont bother about this it works fine
$Preview = trim_display(140,$content); 
function trim_display($size,$string)
    {

        $trim_string = mb_substr($string, 0, 150,'UTF-8');
        echo "<br/> here";
        echo utf8_decode($trim_string);
        return $trim_string;
    }

The error supplied on codepad:

Warning: file_get_contents(http://crewow.com/CSS_Layout_Tutorial.php): failed to open stream: No such file or directory on line 3

Fatal error: Call to undefined function mb_substr() on line 9


回答1:


mbstring extension is not installed in your apache, you need to install that.

Fatal error: Call to undefined function mb_substr() - means that “mbstring” PHP extension is not installed or not enabled on your hosting server.

mbstring provides multibyte specific string functions that help you deal with multibyte encodings in PHP. In addition to that, mbstring handles character encoding conversion between the possible encoding pairs. mbstring is designed to handle Unicode-based encodings such as UTF-8 and UCS-2 and many single-byte encodings for convenience



来源:https://stackoverflow.com/questions/20222999/substr-or-mb-substr-does-not-work

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!