#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    3
    Rep Power
    0

    Exclamation [Help]Rss feed filter SimplePie


    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(website/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!
  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,317
    Rep Power
    7170
    If keyword1 and keyword2 are regular expressions, call preg_match twice.

    If they are not, use strpos twice instead (it's faster).

    ie:
    Code:
    if((keyword1 found) && (keyword2 found))
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    3
    Rep Power
    0
    he keyword are words, like "world news"

IMN logo majestic logo threadwatch logo seochat tools logo