column

外部ブログのRSSを取得し表示

CATEGORY PC & Web PHP お勉強 TAG, ,

投稿日:2013年5月2日 更新日:

執筆者:

外部ブログのRSSを取得し表示

simplexml 先生blogからRSS

001


<!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 を表示

002


<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>

アップル – ホットニュース

003


<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 を表示

004


<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ソング

005


<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>

コメントを残す

関連記事

PREV

WordPress〜PHP+DBで本格的なWebシステムを作るー続き!

NEXT

GoogleAnalytics〜QRコード〜Google Maps API

外部ブログのRSSを取得し表示

side bar

メニューはこちら

メニューはこちら