【发布时间】:2012-01-27 11:05:56
【问题描述】:
我对 PHP 和 XML 还很陌生,并且遇到了一个与 xml 提要有关的特定问题。在 XML 数据中,每个新闻报道都有一个字段“article_content”,该字段具有唯一的属性 (id)。 我需要能够根据从索引页面创建的 URL 在页面上显示这个故事,该页面显示所有故事(url 的示例是 path/to/file/newsstory.php?storyid=19837775),其中 storyid 匹配 id文章内容字段中的属性。
任何人都可以帮忙,因为我在这里把我的头从墙上敲下来!
更新:
XML 格式如下(每个故事的新文章内容)
<channel>
<article_content id="19837775" status="A">
<title>title of article 1</title>
<date>20120127</date>
<time>10:18:00</time>
<body>main body of story 1 here</body>
<introduction>intro text here</introduction>
<abstract></abstract>
<by_line></by_line>
<category_id>0103</category_id>
</article_content>
[...]
我得到的php代码是:
<?php
$xml = new SimpleXMLElement($rss);
$results = array ();
foreach ($xml->channel->article_content[id] as $item) {
echo "<h3>".$item->title."</h3>";
echo nl2br ($item->body->asXML());
}
?>
【问题讨论】:
-
请添加 XML 和您拥有的代码 ....SimpleXML 可能是前进的方向 ....
-
XML 格式如下(每个故事的新文章内容)
我得到的php代码是: channel->article_content[id] as $item) {echo "文章 1 的标题 20120127 这里是故事1的主体这里是介绍文字 0103 ".$item->title."
"; echo nl2br ($item->body->asXML()); } ?>
标签: php xml xml-parsing