 | <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <body> <?php $localstore = "/var/root/rss.xml";
# ファイルからDOMを生成 $doc = new DOMDocument(); $doc->load($localstore);
# XPathの準備 $xpath = new DOMXPath($doc); $xpath->registerNamespace('rss', $doc->documentElement->lookupNamespaceURI(null));
# フィードのタイトル $feed_title = htmlspecialchars($xpath->query('rss:channel/rss:title')->item(0)->nodeValue); printf("<h1>%s</h1>", $feed_title); print "<dl>";
#フィードのアイテムを取り出す $items = $xpath->query('//rss:item'); foreach($items as $item) { # アイテムの中からタイトルやリンクを取りだす $title = htmlspecialchars($xpath->query('rss:title', $item)->item(0)->nodeValue); $link = htmlspecialchars($xpath->query('rss:link', $item)->item(0)->nodeValue); $description = htmlspecialchars($xpath->query('rss:description', $item)->item(0)->nodeValue); printf("<dt><a href=\"%s\">%s</a></dt>", $link, $title); printf("<dd>%s</dd>", $description); } print "</dl>"; ?> </body> </html>
|  |