2011-08-31 136 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