php解析html文件(php 解析)

lxf2023-03-27 08:18:01

PHP Simple HTML DOM 分析器显然是相当少的html文件分析工具,可以在服务器端使用类似jquery的dom查找和修改。该分析器目前支持PHP5。

然而,这首先对html进行了标签分析,占用了大量的内存。在分析更复杂的html文件时,它甚至占用了超过10M的内存,现在在高并发的情况下是不可接受的。

当您加载5个、10个或更多的文档时,用完一个后清理内存:

<?php$html->clear();?>

有兴趣的朋友可以访问该项目的地址为:http://simplehtmldom.sourceforge.net/ 。

本分析中文手册的在线地址为:http://www.ecartchina.com/php-simple-html-dom/manual.htm。

您还可以上传到CSDN的离线版:


本文提供了类似的div查找和修改操作方法

<?phplibxml_use_internal_errors(true) ;$doc = new DOMDocument();// We don't want to bother with white spaces$doc->preserveWhiteSpace = false;$doc->loadHTMLFile("testdoc.html");$xpath = new DOMXPath($doc);//查找带aconf_edit_sectiondiv元素$query = '//div[@aconf_edit_section]';//$entries = $xpath->query($query);$entries=$xpath->query($query);foreach ($entries as $entry) {    //echo  " {$entry->nodeValue}
"; print_r($entry);}// $rs = $dom->getElementById("test");// echo $rs->nodeValue;// print_r($entries->save('xxx.html'));function domNodeList_to_string($DomNodeList) { $output = ''; $doc = new DOMDocument; $i=0; while ( $node = $DomNodeList->item($i) ) { // import node $domNode = $doc->importNode($node, true); // append node $doc->appendChild($domNode); $i ; } $output = $doc->saveXML(); $output = print_r($output, 1); // I added this because xml output and ajax do not like each others //$output = htmlspecialchars($output); return $output;}echo domNodeList_to_string($entries);?>



http://hi.baidu.com/tdweb/itemac600ed81dbc387d

PHP DOMXpath 查询表达式详解

http://blog.csdn.net/wmsjlihuan/article/details/9000790

XPath 语法

http://www.w3school.com.cn/xpath/xpath_syntax.asp