我正在尝试解析一些非英语页面并提取相关信息,然后在不同的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;
我还附上了如何显示文字的屏幕截图。
如何以原始语言显示提取的文本?我真的很感激你的帮助。
答案 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文件中。