Hey all, I have an rss feed that is stored in a database. I'm trying to search through this feed using preg_match(). What I want to do is extract all the items that contain my search term. So I guess what I have to do is match /<item> [whatever] $term [whatever] </item>/. I've been trying to get a regular expression working, but with no luck... I'd really appreciate any help you can give me. Thanks
If it's an XML feed couldn't you use just SimpleXML and a basic loop/array mashup to get the information you need? Dan.
Hey and thanks a lot for your answer Wouldn't it be just as quick to simply search through it with a preg_match? Even if I use simpleXML, I'll still need to do the search...
<?php $url = 'http://www.wiredbyduffy.com/rss/wbdrss.xml'; $term = 'Sudoku'; $insensitive = true; /* Example */ $feed = strtr(file_get_contents($url), "\t\n\r", ' '); preg_match_all('/<item>(.*?'.$term.'.*?)<\/item>/' . ($insensitive ? 'i' : ''), $feed, $items); print_r($items); // Example output. ?> PHP:
Well here's what I do to handle rss feeds. $rss = simplexml_load_file('http://www.site.com/rss.php'); foreach ($rss->channel->item as $x) { $x = (Array) $x; // Don't like handling objects, typecast to array // Do your thing here } PHP: