1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

simplepieの使い方

Last updated at Posted at 2017-01-05

simplepieの使用方法がググってもあまり無かったので取り敢えず役に立つかなと思って投稿。


$rss="http://headlines.yahoo.co.jp/rss/zdn_pc-c_sci.xml";

$feed=new SimplePie();
$feed->set_feed_url($rss);
$feed->enable_cache(false);
$feed->init();
$feed->handle_content_type();

foreach($feed->get_items() as $item) {
	$title = trim($item->get_title());
	$link = trim($item->get_permalink());
	$content=$item->get_content();
	preg_match("/src=\"https?:\/\/[\w\/\.\-_]+(\.)+(png|jpe?g|gif)?/msi",$content,$match);
	$img=str_replace(array("src=\"","'"),"",$match[0]);
 
        print "<a href=\"$link\" target=\"_blank\">$title</a><br>";
        if(!isset($match[0])){print "<img src=\"$img\">";}else
        {return false;}                    

}
1
2
0

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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?