RSS

RSSの練習でいくつかのRSSをまとめたページを作りました。

http://yuto-m.sakura.ne.jp/admin/assignment/php/rss/

以下コードです。

<?php
  $rss = simplexml_load_file("http://www.meiji.co.jp/news/meiji_press.xml");
  $i = 0;
  $suntry = array();
  foreach ($rss->channel->item as $item) {
    if($i++ > 4) { break; }
    $suntry[$i]['link'] = $item->link;
    $suntry[$i]['title'] = $item->title;
    $suntry[$i]['date'] = date('Y年m月d', strtotime($item->pubDate));
    $suntry[$i]['des'] =$item->description;
  }

  $rss = simplexml_load_file("http://www.kirin.co.jp/rss/news/release.rdf");
  $kirin = array();
  $i = 0;
  foreach ($rss->item as $item) {
    $dc = $item->children('http://purl.org/dc/elements/1.1/');
    if($i++ > 4) { break; }
    $kirin[$i]['link'] = $item->link;
    $kirin[$i]['title'] = $item->title;
    $kirin[$i]['date'] = date('Y年m月d', strtotime($dc->date));
    $kirin[$i]['des'] =$item->description;
  }

  $rss = simplexml_load_file("http://rss.sapporobeer.jp/rss/sapporo_1.xml");
  $sapporo = array();
  $i = 0;
  foreach ($rss->channel->item as $item) {
    if($i++ > 4) { break; }
    $sapporo[$i]['link'] = $item->link;
    $sapporo[$i]['title'] = $item->title;
    $sapporo[$i]['date'] = date('Y年m月d', strtotime($item->pubDate));
    $sapporo[$i]['des'] =$item->description;
  }

  $rss = simplexml_load_file("http://www.calpis.co.jp/utility/rss/xml/topics.xml");
  $i = 0;
  $calpis = array();
  foreach ($rss->channel->item as $item) {
    if($i++ > 4) { break; }
    $calpis[$i]['link'] = $item->link;
    $calpis[$i]['title'] = $item->title;
    $calpis[$i]['date'] = date('Y年m月d', strtotime($item->pubDate));
  }
?>
<!doctype html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <title>RSSの練習</title>
  <link rel="stylesheet" href="rss.css">
  <link href='http://fonts.googleapis.com/css?family=Ubuntu' rel='stylesheet' type='text/css'>
</head>
<body>
  <article>
    <h1>RSS DRINK</h1>
    <div id="container">
      <section class="suntry">
        <h2>SUNTRY</h2>
        <?php foreach ($suntry as $value) :?>
        <div class="box">
          <section class="info">
            <h3 class="date"><?php echo $value['date'];?></h3>
            <p class="title"><a href="<?php echo $value['link'];?>"><?php echo $value['title'];?></a></p>
          </section><!-- date end -->
        </div><!-- box end -->
        <?php endforeach ;?>
      </section><!-- suntry end -->
      <section class="kirin">
        <h2>KIRIN</h2>
        <?php foreach ($kirin as $value) :?>
        <div class="box">
          <section class="info">
            <h3 class="date"><?php echo $value['date'];?></h3>
            <p class="title"><a href="<?php echo $value['link'];?>"><?php echo $value['title'];?></a></p>
          </section><!-- date end -->
        </div><!-- box end -->
        <?php endforeach ;?>
      </section><!-- kirin end -->
      <section class="calpis">
        <h2>CALPIS</h2>
        <?php foreach ($calpis as $value) :?>
        <div class="box">
          <section class="info">
            <h3 class="date"><?php echo $value['date'];?></h3>
            <p class="title"><a href="<?php echo $value['link'];?>"><?php echo $value['title'];?></a></p>
          </section><!-- date end -->
        </div><!-- box end -->
        <?php endforeach ;?>
      </section><!-- calpis end -->
      <section class="sapporo">
        <h2>SAPPORO</h2>
        <?php foreach ($sapporo as $value) :?>
        <div class="box">
          <section class="info">
            <h3 class="date"><?php echo $value['date'];?></h3>
            <p class="title"><a href="<?php echo $value['link'];?>"><?php echo $value['title'];?></a></p>
          </section><!-- date end -->
        </div><!-- box end -->
        <?php endforeach ;?>
      </section><!-- sapporo end -->
    </div>
  </article>
</body>
</html>
@charset "utf-8";
  /* Eric Meyer's Reset CSS v2.0 - http://cssreset.com */
  html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video{border:0;font-size:100%;font:inherit;vertical-align:baseline;margin:0;padding:0}article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section{display:block}body{line-height:1}ol,ul{list-style:none}blockquote,q{quotes:none}blockquote:before,blockquote:after,q:before,q:after{content:none}table{border-collapse:collapse;border-spacing:0}

  body{
    font-family: "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
    letter-spacing: 1px;
    line-height: 1.2;
  }
  a{
    text-decoration: none;
    color: black;
  }
  a:hover{
    text-decoration: underline;
  }
  h1{
    text-align: center;
    font-size: 50px;
    margin: 30px;
  }
  #container{
    width: 960px;
    margin: 0 auto;
  }
  #container>section{
    overflow: hidden;
    margin-bottom: 30px;
    padding-bottom: 30px;
    border-bottom: 2px solid #363636;
  }
  section h2{
    text-align: center;
    font-size: 50px;
  }
  section h2,section .box{
    width: 300px;
    box-sizing: border-box;
    padding: 10px 20px;
    display: inline-block;
    vertical-align: top;
    font-family: 'Ubuntu', sans-serif;
  }
  .suntry h2{
    color: #3f85ff;
    padding-top: 30px;
  }
  .kirin h2{
    color: #f11f0e;
    padding-top: 30px;
  }
  .calpis h2{
    color: #9bc9e3;
    padding-top: 15px;
  }
  .sapporo h2{
    color: #e3d70b;
    padding-top: 30px;
  }
  .box h3{
    font-size: 18px;
    margin-bottom: 10px;
    padding: 2px 10px;
    border-left: 5px solid #6eb3ff;
  }
  .box .title{
    color: #353636;
    padding-left: 8px;
  }