Skip to content

Instantly share code, notes, and snippets.

@arslnb
Created November 14, 2012 12:05
Show Gist options
  • Save arslnb/4071764 to your computer and use it in GitHub Desktop.
Save arslnb/4071764 to your computer and use it in GitHub Desktop.
Fetching site data via PHP
<html>
<body>
<?php
function getFeed($feed_url) {
$content = file_get_contents($feed_url);
$x = new SimpleXmlElement($content);
echo "<ul>";
foreach($x->channel->item as $entry) {
echo "
<li>
<a href='$entry->link' title='$entry->title'>" . $entry->title . "</a>
</li>
<li>".$entry->description."</li>";
}
echo "</ul>";
}
?>
/*Enter the RSS feed URL of your target site*/
<?php getFeed("http://rss.example.com/something.xml"); ?>
</body>
</html>
@xeoncross
Copy link

You can read both RSS and ATOM with something like this (not tested).

// Feed might be ATOM or RSS
$items = isset($x->channel) ? $x->channel : $x->entry;

foreach($items as $item)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment