Search code examples
phpwordpressrssadsautoblogged

Selection and Deletion of a tag with specific keyword in WordPress


I use an auto blogging plugin that allows me aggregate RSS feeds from certain sites to fill the gap in my blog in times I don't post in, the idea that posts are injected with ads like AdSense URLs with random dynamic links but usually starts with certain URLS, here is a code snippet:

src="http://rss.feedsportal.com/c/669/f/9809/s/3b7b71e8/sc/5/mf.gif" border="0" /><br clear='all'/><br /><br /><a href="http://da.feedsportal.com/r/199108411625/u/49/f/9809/c/669/s/3b7b71e8/sc/5/rc/1/rc.htm" rel="nofollow"><img src="http://da.feedsportal.com/r/199108411625/u/49/f/9809/c/669/s/3b7b71e8/sc/5/rc/1/rc.img" border="0" /></a><br /><a href="http://da.feedsportal.com/r/199108411625/u/49/f/9809/c/669/s/3b7b71e8/sc/5/rc/2/rc.htm" rel="nofollow"><img src="http://da.feedsportal.com/r/199108411625/u/49/f/9809/c/669/s/3b7b71e8/sc/5/rc/2/rc.img" border="0" /></a><br /><a href="http://da.feedsportal.com/r/199108411625/u/49/f/9809/c/669/s/3b7b71e8/sc/5/rc/3/rc.htm" rel="nofollow"><img src="http://da.feedsportal.com/r/199108411625/u/49/f/9809/c/669/s/3b7b71e8/sc/5/rc/3/rc.img" border="0" /></a><br /><br /><a href="http://da.feedsportal.com/r/199108411625/u/49/f/9809/c/669/s/3b7b71e8/sc/5/a2.htm"><img src="http://da.feedsportal.com/r/199108411625/u/49/f/9809/c/669/s/3b7b71e8/sc/5/a2.img" border="0" /></a><img width="1" height="1" src="http://pi.feedsportal.com/r/199108411625/u/49/f/9809/c/669/s/3b7b71e8/sc/5/a2t.img" border="0" /><img src="http://feeds.feedburner.com/~r/techradar/allnews/~4/tWczqbBA1yg" height="1" width="1" /><br />

The idea that all injected tags include "*feedsportal.com", how can I select the whole tag line that includes this term and replace it or delete it in WordPress?

Thanks!


Solution

  • If you want to remove all tags containing the keyword feedsportal.com you can try something like this..

    // Replace all matches
    $str = preg_replace("/\<a.*?feedsportal\.com.*?\>.*?\<\/a\>/is","",$str);
    
    // Collect matches
    preg_match_all("/\<a.*?feedsportal\.com.*?\>.*?\<\/a\>/is",$str,$matches);
    
    // Show matches
    print "<pre>";
    print_r($matches);
    print "</pre>";