2011-11-21 64 views
0

我正在研究解析我學校的HTML「組」頁面的PHP解析器。這些頁面具有基於課程名稱和其他幾個變量的唯一URL。該頁面由一堆HTML <table>組成。PHP DOM文檔LoadHTML文件被括號中斷

從網址加載HTML可以正常工作,直到文件內容中出現)。然後它只是停止加載,只存儲它到目前爲止所得到的。顯然,加載的HTML不是由我創建的,我無法阻止這些字符在HTML代碼中。

但是,當我在本地使用MAMP運行它時,它工作正常。我試圖尋找答案,但沒有找到任何解決我的問題。

如何在加載之前轉義這些字符?

我目前的PHP:

$dom = new DOMDocument; 
libxml_use_internal_errors(true); // the HTML i parse contains a lot of unclosed tags, this to prevent the errors from displaying on the page 
$dom->loadHTMLFile('http://isarog.hhs.nl/Web_Site/HHS/ICTM/Public/Iris_Roster/Timetables/11_2/11_2-CMD-4vt-p2.html'); 

echo $dom->getElementsByTagName('html')->item(0)->nodeValue; 
+0

AFAIK括號在html中沒有意義,你確定沒有別的東西嗎?如果你創建一個相同的頁面但沒有括號,並加載它,它是否工作? –

+0

我還沒有嘗試過,但是當我回應''標籤的'nodeValue'時,它會顯示所有內容,直到該括號開始發揮作用。 – Joey

+0

呃......試試那個......圓括號之外還有什麼? –

回答

0

這個問題解決了我的問題:Remove control characters from php String

顯然有在我的HTML輸入有不可見字符是造成負載功能停止閱讀。以下清除全部:

$str = file_get_contents('http://isarog.hhs.nl/Web_Site/HHS/ICTM/Public/Iris_Roster/Timetables/11_2/11_2-CMD-4vt-p2.html'); 
$str = mb_convert_encoding($str, 'utf-8', mb_detect_encoding($str)); 

$str = preg_replace('/[\x00-\x1F\x7F]/', '', $str); 
$str = ereg_replace("[[:cntrl:]]", "", $str); 

$dom = new DOMDocument; 
libxml_use_internal_errors(true); // Screw al die markup syntax errors dan ook 
$dom->loadHTML($str);