过去1小时,我一直在摸它的头。是否有任何可靠的方法从HTML页面提取仅文本PHP从html页面提取所有文本
以及其他任何内容(代码,图像,链接,样式,脚本)。我试图提取html文档正文内的所有文本。
这包括段落,纯文本和表格数据..
到目前为止,我已经尝试simplehtmldom
解析器也file_get_contents
但他们两人都没有工作。这里是代码:
<?php
require_once "simple_html_dom.php";
function getplaintextintrofromhtml($html) {
// Remove the HTML tags
$html = strip_tags($html);
// Convert HTML entities to single characters
$html = html_entity_decode($html, ENT_QUOTES, 'UTF-8');
return $html;
}
$html = file_get_contents('http://www.thefreedictionary.com/contempt');
echo getplaintextintrofromhtml($html);
?>
下面是输出的截图:
https://docs.google.com/file/d/0B-b63LoI1gSfaGhpR0NvdUtlbW8/edit?usp=drivesdk
正如你可以看到它显示的是奇怪的输出甚至没有显示整个页面的文本
http://php.net/manual/en/book.curl.php和用strip_tags() – EL3PHANTEN 2014-11-25 10:42:54
你想要提取什么?其不清楚。最终的输出应该是什么? '
'内的内容? – Ghost 2014-11-25 10:48:08编辑我的问题@Ghost – 2014-11-25 10:49:55