首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >php dom load不会加载变量吗?

php dom load不会加载变量吗?
EN

Stack Overflow用户
提问于 2012-09-01 23:17:33
回答 1查看 563关注 0票数 1

我之前的页面工作得很好,直到我尝试将它切换为从变量加载xml文件。现在它不显示任何信息。我想做的是做一个包含"xml“文件夹中所有文件的下拉框列表,然后能够在列表框中选择其中一个选项,然后扫描该文件并显示其信息。

XML文件:

代码语言:javascript
复制
<?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>

代码:

代码语言:javascript
复制
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

我应该避免在文件名中使用空格吗?

表单代码:

代码语言:javascript
复制
<form name="xmlselect" method="post" action="convertxml.php">
<select name="xml">
<?php echo getXMLFiles(); ?>
</select>
<input type="submit" value="Submit" />
</form>

我对该页面的完整代码:

代码语言:javascript
复制
<?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/>';



} 

}
?> 
EN

回答 1

Stack Overflow用户

发布于 2012-09-02 00:28:28

答案是首先将post转换为一个变量,我需要包括文件的确切位置。

代码语言:javascript
复制
$file = $_POST['xml'];
$loc = 'E:/xampp/htdocs/sale/xml/'.$file;
$dom = new DOMDocument();  
$dom->load($loc); 
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12228935

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档