Last active
January 22, 2016 08:56
-
-
Save ecchie/f7ae5c249d108a5cca40 to your computer and use it in GitHub Desktop.
amazon rss widget
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
print '<ul class="ranking">'; | |
/* 設定 */ | |
//RSS | |
$rss = 'http://www.amazon.co.jp/gp/rss/bestsellers/videogames/ref=zg_bs_videogames_rsslink'; | |
//件数 | |
$limit = 5; | |
$data = simplexml_load_string(file_get_contents($rss),'SimpleXMLElement', LIBXML_NOCDATA); | |
$i = 1; | |
foreach($data->channel->item as $value){ | |
if($i<=$limit){ | |
$title = (string)$value->title; | |
$link = (string)$value->link; | |
preg_match('@<img src="(https?|ftp)(:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)" alt="@is', (string)$value->description, $match); | |
$img = !empty($match[2]) ? $match[1]. $match[2] : ''; | |
preg_match('@<img src="(https?|ftp)(:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)" width="64" height="12"@is', (string)$value->description, $match); | |
$rate = !empty($match[2]) ? $match[1]. $match[2] : ''; | |
preg_match('@<strike>(.*?)</strike>(.*?)</font>@', (string)$value->description, $price); | |
print <<< EOF | |
<li class="ranking_box clerfix"> | |
<div class="raking_left"> | |
<div class="ranking_rank">${i}位</div> | |
<div class="ranking_img"><img src="${img}" width="80px" /></div> | |
</div> | |
<div class="ranking_right"> | |
<div class="ranking_name"><a href="${link}" target="_blank">${title}</a></div> | |
<div class="ranking_rate"><img src="${rate}"></div> | |
<div class="ranking_price_new">新品${price[1]} 価格 ${price[2]}</font></div> | |
</div> | |
</li> | |
EOF; | |
} | |
$i++; | |
} | |
print '</ul>'; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment