Skip to content

Instantly share code, notes, and snippets.

@commuterjoy
Created September 11, 2011 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save commuterjoy/1209805 to your computer and use it in GitHub Desktop.
Save commuterjoy/1209805 to your computer and use it in GitHub Desktop.
Rewrite the link of an RSS feed to that of the first anchor in the description
include('Zend/Feed/Rss.php');
include('Zend/Dom/Query.php');
$feed = new Zend_Feed_Rss('http://example.com/rss');
foreach ($feed as $item) {
# where feed contains an <a href="" />, use that as the RSS <link> value
$dom = new Zend_Dom_Query(html_entity_decode($item->description()));
$anchor = $dom->query('a');
if ( count($anchor) > 0 ) {
$item->link = htmlentities( $anchor->current()->getAttribute('href') );
}
}
header('Content-type: application/xml');
echo $feed->saveXml();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment