Skip to content

Instantly share code, notes, and snippets.

@hjst hjst/feed-fixer.php
Created Sep 25, 2013

Embed
What would you like to do?
Pulls in an overstuffed RSS feed and removes any content:encoded nodes (which are usually superfluous).
<?php
$ch = curl_init("FEED URL GOES HERE");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
curl_setopt($ch, CURLOPT_USERAGENT, "Henry's very friendly feed fetcher v1.1");
$rss_string = curl_exec($ch);
$dom = new DOMDocument();
$dom->loadXML($rss_string);
$contents = $dom->getElementsByTagNameNS('http://purl.org/rss/1.0/modules/content/', 'encoded');
while ($contents->length > 0) {
$contents->item(0)->parentNode->removeChild($contents->item(0));
}
header('Content-Type: text/xml');
print( $dom->saveXML() );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.