Dont worry I am rewriting the tag parser using xml to array heres what I have so far
<?php
echo"hello world!";
?>
pmsl nah only joking I have this
<?php
class tagparse
{
private $data;
private $vals;
function tagparse($DATA, $WHITE=1)
{
$index = array();
$this->data = trim($DATA);
$this->data = str_replace(" ", "[tagparse::space]", $this->data); // fix for
$this->data = preg_replace("/(<(\w+).*?>)(<\/\\2>)/", "\\1[tagparse::empty]\\3", $this->data); // fix for empty tags that do not use ommittag
$this->vals = array();
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, $WHITE);
if ( !xml_parse_into_struct($parser, $this->data, $this->vals, $index) )
die("XML error: ".xml_error_string(xml_get_error_code($parser))." at line ".xml_get_current_line_number($parser));
xml_parser_free($parser);
/*
* The code below is all for using of and empty tags that do not use ommittag
*/
$this->data = str_replace("[tagparse::space]", " ", $this->data);
$this->data = str_replace("[tagparse::empty]", "", $this->data);
for($i = 0;$i<count($this->vals);$i++)
{
if(isset($this->vals[$i]['value']))
{
if(strstr($this->vals[$i]['value'], "[tagparse::space]") !== false)
$this->vals[$i]['value'] = str_replace ("[tagparse::space]", " ", $this->vals[$i]['value']);
if(strstr($this->vals[$i]['value'], "[tagparse::empty]") !== false)
$this->vals[$i]['value'] = str_replace ("[tagparse::empty]", "", $this->vals[$i]['value']);
}
}
}
function outputString()
{
$output = "";
for($i = 0;$i<count($this->vals);$i++)
{
//output whole array into formatted file
$indent = $attribs = "";
if($this->vals[$i]['level'] > 1)
$indent = str_repeat("\t", $this->vals[$i]['level']-1);
if(isset($this->vals[$i]['attributes']))
{
foreach($this->vals[$i]['attributes'] as $key=>$val)
{
$attribs.= " ".$key."=\"".$val."\"";
}
}
switch($this->vals[$i]['type'])
{
case "open":
$output .= $indent."<".$this->vals[$i]['tag'].$attribs.">\r\n";
break;
case "complete":
$ommittag = "";
if(!isset($this->vals[$i]['value']))
$output .= $indent."<".$this->vals[$i]['tag'].$attribs." />"."\r\n";
else
$output .= $indent."<".$this->vals[$i]['tag'].$attribs.">".$this->vals[$i]['value']."</".$this->vals[$i]['tag'].">"."\r\n";
break;
case "close":
$output .= $indent."</".$this->vals[$i]['tag'].">\r\n";
break;
}
}
return $output;
}
function outputArr()
{
return str_replace("1", "", print_r($this->vals));
}
}
?>
any ideas for this class??? im already adding functionality to it