【问题标题】:convert xml to html through php通过php将xml转换为html
【发布时间】:2014-01-31 13:06:36
【问题描述】:

我想转换这个输出 http://www.akwl.de/notdienst/xml.php?a=3&m=koord&w=51.954541;7.614748&z=2012-1-16;2012-1-22 成一个样式化的 html。

这是我的尝试...

<?php 
$xmlFile = 'http://www.akwl.de/notdienst/xml.php?a=3&m=koord&w=51.954541;7.614748&z=2012-1-16;2012-1-22';  
if (file_exists($xmlFile)) { 
    $xml = simplexml_load_file($xmlFile); 
    foreach ( $xml->interpret as $user )   
        {   
               echo 'Id: ' . $user['id'] . '<br>';   

           echo 'Datum: ' . $user->datum . '<br>';   
           echo 'Apotheke: ' . $user->Apotheke . '<br><br>';       
        }   

} else { 
    exit("File $xmlFile not found."); 
} 
?>

【问题讨论】:

标签: php html xml


【解决方案1】:

这里的问题是file_exists 查看local 文件系统,而不是remote 服务器,并且由于您没有该文件locally - 它会运行else 的一部分声明。

你可以这样做:

<?php 

    $file = 'http://www.aknr.de/notdienst/exporte/xml.php?m=koord&w=51.494088;6.772776&z=2014-01-01;2014-01-31&a=2&c=iso';

    if(!$xml = simplexml_load_file($file)){
        echo "file not found!";
    } else {
        echo "<pre>";
        print_r($xml);
        echo "</pre>";    
    }

?>

然后你可以遍历元素,并显示数据,

【讨论】:

  • 谢谢你的工作...需要添加 php.ini with allow_url_fopen = on
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-06-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-18
  • 2016-08-17
  • 2013-06-18
相关资源
最近更新 更多