/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
Class HTML_Parser { // 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 { } } }