View Single Post
Old 01-21-2009, 06:07 PM   #3 (permalink)
Salathe
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Here's just one idea. The process is simply: find items which don't belong to our requested category and delete them.

PHP Code:
/**
 * Filtering an RSS feed by category.
 */

// Load the XML feed
$dom = new DOMDocument();
$dom->load('http://www.talkphp.com/external.php?type=RSS2');


// Query for the items we want to throw away
$xpath = new DOMXPath($dom);
$nodes $xpath->query('//item[not(category = "General")]');

// Remove those unwanted items
foreach ($nodes as $node)
{
    
$node->parentNode->removeChild($node);
}

// Output the filtered document
header('Content-Type: application/xml; charset='.$dom->encoding);
echo 
$dom->saveXML(); 
Salathe is offline  
Reply With Quote