PHP:刮掉非英文的html页面

时间:2013-10-04 07:10:31

标签: php character-encoding non-english

我正在尝试解析一些非英语页面并提取相关信息,然后在不同的html页面中显示提取的信息。但是我可以使用PHP Dom解析器(simple_html_dom)成功提取相关文本,但是我无法以原始语言显示提取的文本。 我制作了简单的脚本,只需从URL获取文本并显示

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 个答案:

答案 0 :(得分: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