php html解析器
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php html解析器相关的知识,希望对你有一定的参考价值。
// Private properties var $_parser; var $_html; var $strXmlData; var $_level = 0; var $_outline; var $xml_error = false; var $xml_error_code; var $xml_error_string; var $xml_error_line_number; function get_html () { return $this->_html; } function parse($strInputXML) { // Translate entities $strInputXML = $this->translate_entities($strInputXML); if (!$this->strXmlData) { $this->xml_error = true; return false; } return $this->output; } function tagOpen($parser, $name, $attr) { // Increase level $this->_level++; // Create tag: $newtag = $this->create_tag($name, $attr); // Build tag // Add tag // Add tag to this level $this->_tags[$this->_level] = $tag; // Add to HTML $this->_html .= $newtag; // Add to outline $this->_outline .= $this->_level . $newtag; } function create_tag ($name, $attr) { // Create tag: # Begin with name # Create attribute list foreach ($attr as $key=>$val) { } # Finish tag case 'br': case 'input': $tag .= ' /'; break; } $tag .= '>'; return $tag; } function tagData($parser, $tagData) { } else { } } } function tagClosed($parser, $name) { // Add to HTML and outline case 'br': case 'input': break; default: } // Get tag that belongs to this end $tag = $this->_tags[$this->_level]; $tag = $this->create_tag($tag['name'], $tag['attr']); // Try to get innerHTML $regex = '%' . preg_quote($this->_level . $tag, '%') . '(.*?)' . preg_quote($this->_level . '</' . strtolower($name) . '>', '%') . '%is'; // Get innerHTML $innerhtml = $matches['1']; } // Remove level identifiers $this->_outline = str_replace($this->_level . '</' . strtolower($name) . '>', '</' . strtolower($name) . '>', $this->_outline); // Add innerHTML } // Fix tree // Decrease level $this->_level--; } function translate_entities($xmlSource, $reverse =FALSE) { static $literal2NumericEntity; foreach ($transTbl as $char => $entity) { } } if ($reverse) { } else { } } }
以上是关于php html解析器的主要内容,如果未能解决你的问题,请参考以下文章