substr() 或 mb_substr() 不起作用 [英] substr() or mb_substr() does not work

查看:62
本文介绍了substr() 或 mb_substr() 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 file_get_content() 解析网页内容,然后从中获取纯文本.

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

现在我想从明文中捕获前 150 个字符.我在这里工作.

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

键盘上的演示:演示

$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;
    }

键盘上提供的错误:

警告:file_get_contents(http://crewow.com/CSS_Layout_Tutorial.php):未能打开流:第 3 行没有这样的文件或目录

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

致命错误:在第 9 行调用未定义的函数 mb_substr()

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

推荐答案

mbstring 扩展没有安装在你的 apache 中,你需要安装.

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

致命错误:调用未定义的函数 mb_substr()- 表示您的托管服务器上未安装或未启用mbstring"PHP 扩展.

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

mbstring 提供了多字节特定的字符串函数,可帮助您处理 PHP 中的多字节编码.除此之外,mbstring 处理可能的编码对之间的字符编码转换.mbstring 旨在处理基于 Unicode 的编码,例如 UTF-8 和 UCS-2 以及为方便起见的许多单字节编码

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

这篇关于substr() 或 mb_substr() 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆