0

こんにちはプロ私はphpプログラミングの助けを求めてもう一度ここに来ます。私はこの言語に本当に慣れていませんが、かなり学んでいます。言っ途切れる。

とにかく今は困っていますが、中にたくさんのフォルダが入っているzipファイルをテキストファイルで読み、テキストファイル自体の内容である文字列変数(テキストファイルの名前ではありません!)に保存したいと思います。これは私のタスクを達成する例を私に提供します。

具体的には、実際にはすべてのxmlファイルをzip形式で読み取ろうとしています。しかし、テキストファイルの例はうまくいくでしょう。

これは私が現在持っているものです:

<?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
4

2 に答える 2

1

上記のコードは正常に動作します。問題は xml ファイルにあります。これらのエラーはすべて、xml バリデーターから発生しています。

于 2012-08-10T17:43:23.703 に答える
1

やっと手に入れました。私を助けてくれてありがとう。だから私はこれで来ました。

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);
  }
}
于 2012-08-14T11:33:55.777 に答える