Jump to content

Broken XML Reader Script


mattd8752

Recommended Posts

For some reason, this script isn't fully running through.

 

It is outputting 1<main>

When it should also print_r an array.

 

Heres the code, if anyone could find my problem, it would be appreciated.

<?php
class xmlread
{
   function input($cont){
   $this->data = $cont;
   }

   function read($main){
   $data = $this->data;
   $line = 0;
   $level = 0;
   $tag = 0;
      while($line < sizeof($data)){
      $inxml = FALSE;
         if($inxml == FALSE){
            if(trim($data[$line]) == "<".trim($main).">"){
            $inxml == TRUE;
            $level = 1;
            echo "1";
            echo $data[$line];
            }
      
         }else{
            if($level == 1){
               echo "2";
               if(ereg("^<", trim($data[$line])) && ereg(">$", trim($data[line])) && !ereg("^</", trim($data[$line]))){
               $tag = explode("<", $data[$line]);
               $tag = explode(">", $tag[1]);
               $tag = $tag[0];
               $level = 2;
               }elseif("<".$main.">" == trim($data[$line])){
               echo "3";
               $inxml = FALSE;
               }
            }elseif($level == 2){
               if(ereg("^</", trim($data[$line])) && ereg(">$", trim($data[$line]))){
               $level = 1;
               $tag = 0;
               }else{
               $tagb = explode("<", $data[$line], 1);
               $tagb = explode(">", $tagb[1], 1);
               $tagc = $tagb[0];
               $tagb = explode("<", $tagb[1], 1);
               $fill = $tagb[0];
               $tagb = explode(">", $tagb[1], 1);
                  if($tagb[0] != $tagc){
                  die("Error: XML");
                  }else{
                  $return[$tag][$tagc] = $fill;
                  }
               }
            }
         }
      $line++;
      }
   return $return;
   }
}

$test = new xmlread;
$page = file('test.xml');
$test->input($page);
print_r($test->read('main'));
?>

 

Link to comment
https://forums.phpfreaks.com/topic/42143-broken-xml-reader-script/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.