2013-10-04 56 views
-1

我想解析一些非英文頁面並提取相關信息,然後在不同的html頁面中顯示提取的信息。不過,我可以使用PHP Dom解析器(simple_html_dom)成功提取相關文本,但是我無法以原始語言顯示提取的文本。 我做了簡單的腳本,將簡單地從URL獲取文本並顯示PHP:刮非英文html頁面

 
header('Content-type: text/html; charset=utf-8'); 
$html = str_get_html(utf8_encode(file_get_contents('http://www.bhaskar.com/article-ht/INT-washington-capitol-hill-shooting-suspected-woman-shot-dead-by-police-4393270-PHO.html'))); 
echo $html; 

我還附上的文字是如何顯示的屏幕截圖。 enter image description here

如何以原始語言顯示提取的文本?我會很感激任何幫助。

回答

1

通過不加入神祕的字符串處理程序,而不是utf8_encode已經utf8_encoded內容:)

<? 
header('Content-type: text/html; charset=utf-8'); 
echo file_get_contents('http://www.bhaskar.com/article-ht/INT-washington-capitol-hill-shooting-suspected-woman-shot-dead-by-police-4393270-PHO.html'); 
?> 

工作得很好這裏,坐在丹麥,只有粘貼到上述空的PHP文件。

enter image description here

+0

感謝您的信息。然而,檢查這一個[前] <? header('Content-type:text/html; charset = utf-8'); echo file_get_contents('http://www.thesamaja.com/news_view.php?news_id=56265'); ?> [/ pre] –