我之前的页面运行良好,直到我尝试将其切换为从变量加载 xml 文件。现在它只是不显示任何信息。我要做的是制作一个包含在“xml”文件夹中找到的所有文件的下拉框列表,然后能够在列表框中选择其中一个选项并扫描该文件并显示其信息。
XML 文件:
<?xml version='1.0' encoding='utf-8'?>
<calibredb>
<record>
<id>5055</id>
<uuid>83885ffc-93d8-41ba-aee2-e5c0ae48fc68</uuid>
<publisher>Now Comics</publisher>
<size>5803436</size>
<title sort="Terminator - The Burning Earth 5, The">The Terminator - The Burning Earth 5</title>
<authors sort="Unknown">
<author>Unknown</author>
</authors>
<timestamp>2012-05-13T19:38:03-07:00</timestamp>
<pubdate>2012-05-13T19:38:03-07:00</pubdate>
<series index="5.0">The Terminator: The Burning Earth</series>
<cover>M:/Comics/Unknown/The Terminator - The Burning Earth 5 (5055)/cover.jpg</cover>
<formats>
<format>M:/Comics/Unknown/The Terminator - The Burning Earth 5 (5055)/The Terminator - The Burning Earth 5 - Unknown.cbr</format>
</formats>
</record>
</clibredb>
代码:
if (isset($_POST['xml']) && $_POST['xml'] != "") {
$loc = $_POST['xml'];
$dom = new DOMDocument();
$dom->load($loc);
foreach ($dom->getElementsByTagName('record') as $e) {
$publisher = $e->getElementsByTagName('publisher')->item(0)->textContent;
$title = $e->getElementsByTagName('title')->item(0)->textContent;
echo 'Title: '.$title.'<br/>';
echo 'Publisher: '.$publisher.'<br/>';
}
}
让我们说$_POST['xml']
= 现在 Comics.xml
我应该避免在文件名中使用空格吗?
表格代码:
<form name="xmlselect" method="post" action="convertxml.php">
<select name="xml">
<?php echo getXMLFiles(); ?>
</select>
<input type="submit" value="Submit" />
</form>
我对该页面的完整代码:
<?php
include("config.php");
include("core.php");
function getXMLFiles() {
if ($handle = opendir("E:/xampp/htdocs/sale/xml")) {
while (false !== ($entry = readdir($handle))) {
if ($entry == "." || $entry == "..") {
}else{
$name = str_replace(".xml", "", $entry);
echo '<option value="'.$entry.'">'.$name.'</option>';
}
}
}
}
if (isset($_REQUEST['xml']) && $_POST['xml'] != "") {
$loc = $_POST['xml'];
$dom = new DOMDocument();
$dom->load($loc);
foreach ($dom->getElementsByTagName('record') as $e) {
$publisher = $e->getElementsByTagName('publisher')->item(0)->textContent;
$title = $e->getElementsByTagName('title')->item(0)->textContent;
echo 'Title: '.$title.'<br/>';
echo 'Publisher: '.$publisher.'<br/>';
}
}
?>