您好专业人士,我再次来到这里寻求 php 编程方面的帮助。我对这门语言真的很陌生,但学得很多。纳夫说。
无论如何,我现在遇到了困难,我想读取一个 zip 文件,其中包含许多包含文本文件的文件夹,并保存在字符串变量(不是文本文件的名称!)中,即文本文件本身的内容。这将为我提供完成任务的示例。
具体来说,我实际上是在尝试读取 zip 中的所有 xml 文件。但是文本文件的示例会很好。
这是我目前拥有的:
<?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();
?>
感谢所有在场的人。格拉西亚斯。
更新
这实际上是精确的输出:
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