使用URL从URL解析ziped XML文件

时间:2017-08-07 08:46:23

标签: php xml parsing xml-parsing unzip

我想从URL和PHP解析XML文件。目前,使用此代码,我可以获得XML文件的内容,但我没有成功使用 simplexml_load_string ,以便将其用作XML内容。

实际上,当我回显 zip 时,文本会显示没有XML标记。你有什么想法吗?谢谢。

<?php
$file = 'http://url_here_.zip';
$newfile = 'tmp_name_file.zip';

if (!copy($file, $newfile)) {
echo "failed to copy $file...\n";}

 $zip = new ZipArchive();

 if ($zip->open($newfile)!==TRUE) {
    exit("cannot open <$filename>\n");
   } else {
    $zip->getFromName('Scrutins_XIV.xml');
    $xml = simplexml_load_string(file_get_contents($zip));
    $zip->close();
   }
 ?>

1 个答案:

答案 0 :(得分:0)

试试这个:

$xml_string = $zip->getFromName('Scrutins_XIV.xml');
if ( $xml_string!= false ) {
    $xml = simplexml_load_string($xml_string);
}
相关问题