Hi,
I'm rather new to php so...I use simplepie to parse rss feed but i want to filter them by keywords
i made this code :

$feed = new SimplePie(); 
$feed->set_feed_url(http://website.name/rss); 
$feed->init(); 
$feed->set_cache_duration (3600); 
$feed->set_timeout(30); 
$feed->handle_content_type(); 
$countItem = 0; 
foreach ($feed->get_items() as $item){ 
$checktitle = $item->get_permalink(); 
//Regex keyword filter 
$pattern = '/keyword1|keyword2/'; 
//If the there is a keyword match, store in $matches array 
if (preg_match($pattern, $checktitle)) { 
        $news[$countItem]= $item; 
        $countItem++; 
} 
}  

This is the filtering part it does it work but, i want all the items that contains both keywords.
I'm not sure that preg_match is the right way to do this but it;s the only thing i got, so please!

Recommended Answers

All 3 Replies

@dalilice

Have you looked over the rather extensive FAQ, Knowledge Base, API documentation that is available at the creators website?

http://simplepie.org/

There is no filtering system in the FAQ, just a file from 3 yaers ago wich i can't find.. so i have to make my own..
It works with 2 preg_matches but i'm still open to sugestions

looks to be a good way of doing it.

Scanning the documentation it seems this is a popular request for v2

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.