Created
September 11, 2011 16:47
-
-
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
This file contains hidden or 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
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