从 URL 中解析带有 PHP 的压缩 XML 文件
Parse a ziped XML file with PHP from an URL
我想从 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();
}
?>
试试这个:
$xml_string = $zip->getFromName('Scrutins_XIV.xml');
if ( $xml_string!= false ) {
$xml = simplexml_load_string($xml_string);
}
我想从 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();
}
?>
试试这个:
$xml_string = $zip->getFromName('Scrutins_XIV.xml');
if ( $xml_string!= false ) {
$xml = simplexml_load_string($xml_string);
}