2011-08-31 137 views
0

我使用PHP 5.2.10运行简单的CentOS 5.5服务器。我试图使用PHP简单的HTML Dom解析器,但我得到一个500服务器错误。下面是该脚本:PHP - 简单的HTML Dom解析器 - 500服务器错误

<?php 
include_once('simple_html_dom.php'); 
$html = file_get_html('http://www.google.com/'); 

正如你所看到的,我还没有做与分析器进行任何事情,除了试图打开一个URL。而那file_get_html导致500服务器错误。

我在httpd错误日志中看不到任何错误。所以我不确定在哪里看问题。 Simple HTML Dom解析器唯一的PHP要求似乎是PHP 5+(检查)和php allow_url_fopen = On(检查)。

+0

有关闭标签那里,对不对? –

+1

在你的php.ini中设置display_errors为on。也许文件不包括在内? –

+1

@OhCaN - 只要没有非php代码,关闭php标签就不需要.php文件。 –

回答

2

自从5.2版本,PHP将产生HTTP响应500如果出现致命错误,并且display_errors设置是关闭的。开启以查看错误,即停止执行脚本。也许文件不包括(错误的权限,路径)和file_get_html()没有被定义,或者file_get_html()会产生一个致命的错误。

1

也许是因为“php-mbstring”模块没有安装?你可以使用ini_set('display_errors', 'On');来检查。

1

根据Vitor的建议,我通过将file_get_html更改为file_get_contents来解决了此问题。因为我想用“查找”功能在simple_html_dom,我不得不那么字符串转换为对象:

$string = file_get_contents(http://thedeadfallproject.com/) 
$object = new simple_html_dom(); 
$object->load($string); // Load HTML from a string