如何从php中的xml中获取数据并在php中创建一个新的页面或url并显示xml的完整内容?

时间:2017-01-25 18:53:12

标签: php xml

    <?xml version="1.0" encoding="utf-8"?>
       <archive>
         <news category="Lorem">
           <headline>Lorem Ipsum</headline>
           <date>January 25th, 2016</date>
           <sortNews>What is Lorem Ipsum?</sortNews>
           <fullNews><b>Lorem Ipsum</b> is simply dummy text of the printing  and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</fullNews>
         </news>
        </archive>

以上是XML文件。假设文件名是archive.xml。

             <?php
                    $xmls=simplexml_load_file("newsArchive.xml") or die("Error: Cannot create object");
                    foreach ($xmls as $xml) { 
                      echo "<h4>" . $xml->headline->asXml() . "</h4>";
                      echo "<h5>" . $xml->date->asXml() . "</h5>";
                      echo "<p>" . $xml->sortNews->asXml() . "</p>";
                    }
              ?>

现在我想在sortnews之后显示一个链接了解更多并打开一个新的php文件或请求某些内容,以便它看起来像那样并显示其他信息的完整新闻文本。

这可能吗?或者我该怎么做?此外,xml文件中可能有多个新闻。

0 个答案:

没有答案