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
I finally got it. Thanks for trying to help me guys. So I just came with this.