LoginSignup
1
1

More than 5 years have passed since last update.

RSS2.0の最新情報を取得

Last updated at Posted at 2015-04-01

RSSの最新だけを取得する方法。
とりあえず2.0の奴だけうまくいったのでメモ。
修正&加筆したものはコチラ


$RSS = simplexml_load_file($url);

foreach($RSS->channel AS $XML){

    $title = $XML->item[0]->title;
    $link  = $XML->item[0]->link;
    $date  = $XML->item[0]->pubDate;

}

何故か

foreach($RSS->channel->item[0] AS $XML)

ってしたら取得できませんでした。

※追記※
この方法だと色々と問題があるらしいので、正しい方法はコメント欄にて。
ちなみに各所でforeachで回しているのは$RSS->channel->itemの場合。
この場合[item]は複数あるのでforeachする必要がある。

1
1
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1