简单的HTML Dom-使用load_file时出现致命错误 [英] Simple HTML Dom - Fatal error when using load_file

查看:210
本文介绍了简单的HTML Dom-使用load_file时出现致命错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试解析一个具有可怕(相信我是)HTML结构的HTML文件,由于这一点以及我的知识不足,我无法编写自己的解析器.后来我尝试使用Simple HTML Dom解析器,因为很多人(同样在SO上)推荐它.

I'm trying to parse an HTML file that has terrible (believe me, it is) HTML structure and because of this and my lack of knowledge, I couldn't write my own parser. Later I tried using Simple HTML Dom parser, because a lot of people (on SO as well) recommend it.

我需要simple_html_dom.php,然后创建了对象.它们似乎起作用,require()函数返回"1",而var_dump()-对象返回一个对象.

I required the simple_html_dom.php, then created the object. They seem to work, the require() function returns "1" and var_dump()-ing the object returns an object.

此后,我尝试按照手册中的说明加载URL,但是无论我尝试使用哪种URL,都遇到致命错误.错误如下:

After this I tried to load the URL as it was done in the manual, but I got a fatal error, no matter what URL I tried. The error was the following:

Fatal error: Call to undefined function mb_detect_encoding() in 
             /home/fema/web/subdomain/devel/www_root/parser/
             simplehtmldom_1_5/simple_html_dom.php on line 988

我检查了988行上的内容,内容如下:

I checked what's on line 988 and it is the following:

// Have php try to detect the encoding from the text given to us.
        $charset = mb_detect_encoding($this->root->plaintext . "ascii", 
                   $encoding_list = array( "UTF-8", "CP1252" ) );

我了解这与字符编码有关,仅此而已.我既没有在Google上也没有在SO上找到任何与此有关的东西.

I understand that this is about character encoding, but that's all. I haven't found anything about this neither with google or on SO.

我的整个代码是(占位符URL):

My whole code is (placeholder URL):

<?php

require('simplehtmldom_1_5/simple_html_dom.php');

// Create a DOM object
$dom = new simple_html_dom();

$dom->load_file('http://www.google.com/');

?>

谁能告诉我该怎么办?或发生此类情况时提供一些建议.

Could anyone please tell me what to do? Or some kind of advice when something like this happens.

谢谢.

推荐答案

您的PHP版本缺少多字节字符串扩展名.这种情况实际上很不常见,除非您使用的是非常老的PHP版本或使用不寻常的编译选项进行编译的版本,因为虽然默认情况下未启用多字节扩展名,但通常将其视为以下一种:最近,每个PHP构建或多或少都具有这些基本扩展.

Your build of PHP is missing the multibyte string extension. It's actually quite unusual for this to be the case, unless you're using a really old build of PHP or one compiled with unusual compile options, as whilst the multibyte extension isn't enabled by default, it is usually considered to be one of the essential extensions that more or less every PHP build has these days.

如果您正在运行旧版本的PHP,我强烈建议您进行升级,如果您的版本比较新,请使用phpinfo()检查是否已安装多字节.如果不这样做,则可能需要从源代码重新安装或重建PHP.

If you're running an old version of PHP I'd strongly recommend upgrading, if you have a fairly recent build, check with phpinfo () that you have multibyte installed. If you don't, then you might need to reinstall or rebuild PHP from source.

如果已安装,则--enable-mbstring应该在编译选项列表中.请参阅有关多字节扩展名的PHP手册,尤其是安装章节,更多细节.

If it's installed, --enable-mbstring should be in the list of compile options. See the PHP manual on the multibyte extension, especially the chapter on installation, for more details.

这篇关于简单的HTML Dom-使用load_file时出现致命错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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