目次
外部ブログのRSSを取得し表示
simplexml 先生blogからRSS
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>外部RSSを取得・表示</title>
<style>
li {
font-size: 0.875em;
line-height: 1.4;
margin-bottom: 4px;
}
</style>
</head>
<body>
<ul>
<?php
$rss = simplexml_load_file("http://d.hatena.ne.jp/css_design/rss");
$i = 1;
foreach ($rss -> item as $item){
if(++$i>5) break;
$dc = $item->children('http://purl.org/dc/elements/1.1/');
$link = $item->link;
$title = $item->title;
$date = date("Y年m月d日",strtotime($dc->date));
//$date =$item->description;
echo "<li><a href=\"$link\" title=\"$title\" target=\"_blank\">$title</a><span>($date)</span></li>\n";
}
?>
</ul>
</body>
</html>
Yahoo! トピックスの RSS を表示
<ul>
<?php
$url = 'http://rss.dailynews.yahoo.co.jp/fc/rss.xml';
$rss = file_get_contents($url);
$xml = simplexml_load_string($rss);
$channel = $xml->channel;
$feed_title = $channel->title;
echo '<h3>'.$feed_title.'</h3>';
echo '<ol>';
foreach ($channel -> item as $item){
if(++$i>5) break;
$dc = $item->children('http://purl.org/dc/elements/1.1/');
$link = $item->link;
$title = $item->title;
$date = date("Y年m月d日",strtotime($dc->date));
$desc = $item->description;
echo "<li><a href=\"$link\" title=\"$title\" target=\"_blank\">$title</a><span>($date)</span></li>\n";
}
echo '</ol>';
?>
</ul>
アップル – ホットニュース
<ul>
<?php
$url = 'http://www.apple.com/jp/main/rss/hotnews/hotnews.rss';
$rss = file_get_contents($url);
$xml = simplexml_load_string($rss);
$channel = $xml->channel;
$feed_title = $channel->title;
echo '<h3>'.$feed_title.'</h3>';
echo '<ol>';
foreach ($channel -> item as $item){
$link = $item->link;
$title = $item->title;
$date = date("Y年m月d日",strtotime($dc->date));
$desc = $item->description;
echo "<li><a href=\"$link\"title=\"$title\">$title</a>($date)</li>\n";
}
echo '</ol>';
?>
</ul>
アップル – 新規追加トップ10の RSS を表示
<ul>
<?php
$url = 'http://ax.itunes.apple.com/WebObjects/MZStore.woa/wpa/MRSS/justadded/sf=143462/limit=10/rss.xml';
$rss = file_get_contents($url);
$xml = simplexml_load_string($rss);
$channel = $xml->channel;
$feed_title = $channel->title;
echo '<h3>'.$feed_title.'</h3>';
echo '<ol>';
foreach ($channel -> item as $item){
$link = $item->link;
$title = $item->title;
$date = date("Y年m月d日",strtotime($dc->date));
$desc = $item->description;
echo "<li><a href=\"$link\"title=\"$title\">$title</a>($date)</li>\n";
}
echo '</ol>';
?>
</ul>
アップル – トップ10ソング
<dl>
<?php
$url = 'http://ax.itunes.apple.com/WebObjects/MZStore.woa/wpa/MRSS/topsongs/sf=143462/limit=10/rss.xml';
$rss = file_get_contents($url);
$xml = simplexml_load_string($rss);
$channel = $xml->channel;
$feed_title = $channel->title;
echo '<h3>'.$feed_title.'</h3>';
echo '<dt>';
foreach ($channel -> item as $item){
$link = $item->link;
$title = $item->title;
$date = date("Y年m月d日",strtotime($dc->date));
$desc = $item->description;
echo "<dd><a href=\"$link\"title=\"$title\">$title</a>($date)</dd>\n";
}
echo '</dt>';
?>
</dl>