支援訓練 62日目

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>Yahoo! トピックスの RSS を表示</title>
</head>
<body>
<h3>RSS2を表示</h3>
<?php
$url ="http://ichisemasashi.hatenablog.com/rss";
$rss = file_get_contents($url);
$xml = simplexml_load_string($rss);

$channel = $xml->channel;
$feed_title = $channel->title;
$date = date('Y.m.d'); 

print '<h3>'.$feed_title.'</h3>';
print '<h4>'.$date.'</h4>';
print '<ol>';
foreach ($channel->item as $item) {
  $link = $item-> link;
  $title = $item-> title;
  $desc = $item-> description;
  $date = date('Y.m.d', strtotime($item->pubDate));

  print "<li><a href=\"$link\"title=\"$title\">$title</a> ($date)</li>\n";
}
print '</ol>';
?>
</body>
</html>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>外部RSS1を取得・表示</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/web-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));

//$desc =$item->description;
print "<li><a href=\"$link\" title=\"$title\" target=\"_blank\">$title</a><span>($date)</span></li>\n";
}
?>
</ul>
</body>
</html>