Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8375797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:16:07+00:00 2026-06-09T15:16:07+00:00

Hello pros I come here once again for help with php programming. I am

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:16:08+00:00Added an answer on June 9, 2026 at 3:16 pm

    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);
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello! I've been programming for a long time but just started developing for android,
Hello friends I am new to TableView.....I want help..please I have to set the
Hello friends a very novice question as I am very new to programming. I
Hello i'm doing a application in php, and i have a list of items
Hello everyone i am trying to format the input number range with php number_format
Hello i have this code var queue = new BlockingCollection<int>(); queue.Add(0); var producers =
Hello I need some help with a bug in Internet Explorer 9. I am
Hello I'm a newcomerin JavaScript language. I started to see some examples of JavaScript
Hello There, I am new to phonegap.I am trying to record a audio clip
hello im am getting JS error : Uncaught SyntaxError: Unexpected identifier here <script type=text/javascript>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.