Q:

PHP read all text files in a zip and save it to a string variable

Hello pros I come here once again for help with php programming. I am really new to the language but learning pretty much. Nuff said.
Anyway I am having a difficulty right now, I want to read a zip file that has many folders inside with text files and be save in a string variable(not the name of the text file!), the content of the text file itself. This will provide me an example of accomplishing my task.
To be specific I am actually trying to read all xml files in a zip. But the example for the text file will do good.
This is what I currently have:
<?php

function comment(){

    $moodle = new Moodle();

    $zip = zip_open('qwerty.zip');

    if ($zip)
    {
        while ($zip_entry = zip_read($zip))
        {
            //echo "Name: " . zip_entry_name($zip_entry). "<br />";

            $data = zip_entry_read($zip_entry);

            $xml = new SimpleXMLElement($data);

            //echo $data;

        }
        zip_close($zip);
    }

}

comment();

?>

Thank you to all the people out there. Gracias.
Update
This is the output actually to be precise:
Warning: SimpleXMLElement::__construct(): Entity: line 28: parser error : expected '>' in D:\xampp\htdocs\project\index.php on line 47

Warning: SimpleXMLElement::__construct(): <component>mod_resource</compon in D:\xampp\htdocs\project\index.php on line 47

Warning: SimpleXMLElement::__construct(): ^ in D:\xampp\htdocs\project\index.php on line 47

Warning: SimpleXMLElement::__construct(): Entity: line 28: parser error : Opening and ending tag mismatch: component line 28 and compon in D:\xampp\htdocs\project\index.php on line 47

Warning: SimpleXMLElement::__construct(): <component>mod_resource</compon in D:\xampp\htdocs\project\index.php on line 47

Warning: SimpleXMLElement::__construct(): ^ in D:\xampp\htdocs\project\index.php on line 47

Warning: SimpleXMLElement::__construct(): Entity: line 28: parser error : Premature end of data in tag file line 25 in D:\xampp\htdocs\project\index.php on line 47

Warning: SimpleXMLElement::__construct(): <component>mod_resource</compon in D:\xampp\htdocs\project\index.php on line 47

Warning: SimpleXMLElement::__construct(): ^ in D:\xampp\htdocs\project\index.php on line 47

Warning: SimpleXMLElement::__construct(): Entity: line 28: parser error : Premature end of data in tag files line 2 in D:\xampp\htdocs\project\index.php on line 47

Warning: SimpleXMLElement::__construct(): <component>mod_resource</compon in D:\xampp\htdocs\project\index.php on line 47

Warning: SimpleXMLElement::__construct(): ^ in D:\xampp\htdocs\project\index.php on line 47

Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in D:\xampp\htdocs\project\index.php:47 Stack trace: #0 D:\xampp\htdocs\project\index.php(47): SimpleXMLElement->__construct('<?xml version="...') #1 D:\xampp\htdocs\project\index.php(85): comment() #2 {main} thrown in D:\xampp\htdocs\project\index.php on line 47

A:

I finally got it. Thanks for trying to help me guys. So I just came with this.
function moodlezip($zipfile) {
  echo "<h1>MOODLE</h1>"."<br />";
  $moodle = new Moodle();

  $zipfile = 'backup-moodle2-course-music_basic-20120806-1359b.mbz';
  $zip = zip_open($zipfile);
  $ziparc = new ZipArchive;

  if ($zip) {
    while ($zip_entry = zip_read($zip)) {
      $file = zip_entry_name($zip_entry);
      //echo "Name: " . $file . "<br />";

      if (strpos($file,'course.xml') !== false) {
        if ($ziparc->open($zipfile) === TRUE) {
          $coursexml =  new SimpleXMLElement($ziparc->getFromName($file));
          $moodle->getCourse($coursexml);
          $ziparc->close();
        } else {
          echo 'failed';
        }
      }
      else if (strpos($file,'forum.xml') !== false) {
        if ($ziparc->open($zipfile) === TRUE) {
          $topicxml =  new SimpleXMLElement($ziparc->getFromName($file));
          $moodle->getTopic($topicxml);
          $ziparc->close();
        } else {
          echo 'failed';
        }
      }
      else if (strpos($file,'questions.xml') !== false) {
        if ($ziparc->open($zipfile) === TRUE) {
          $questionsxml =  new SimpleXMLElement($ziparc->getFromName($file));
          $moodle->getQuestions($questionsxml);
          $ziparc->close();
        } else {
          echo 'failed';
        }
      }
    }
    zip_close($zip);
  }
}

