Created
September 12, 2014 17:50
-
-
Save vladimirlukyanov/54de24ad158c8f8b0ad4 to your computer and use it in GitHub Desktop.
Simple RSS parser
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 | |
$i = 0; // counter | |
$url = "http://www.banki.ru/xml/news.rss"; // url to parse | |
$rss = simplexml_load_file($url); // XML parser | |
// RSS items loop | |
print '<h2><img style="vertical-align: middle;" src="'.$rss->channel->image->url.'" /> '.$rss->channel->title.'</h2>'; // channel title + img with src | |
foreach($rss->channel->item as $item) { | |
if ($i < 10) { // parse only 10 items | |
print '<a href="'.$item->link.'">'.$item->title.'</a><br />'; | |
} | |
$i++; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment