czheng Posted July 15, 2006 Share Posted July 15, 2006 Hey folks. Newcomer here. I've spent the last few days modifying an RSS Reader script I downloaded somewhere, and I've got it running almost exactly how I'd like it. The last thing I'd like to do is, for the following feed([url=http://ma.gnolia.com/rss/full/people/czheng]http://ma.gnolia.com/rss/full/people/czheng[/url]), remove from each ITEM everything from (and including) [code]<b>Tags:[/code] up to (but not including) [code]<description>[/code].I'm guessing it would be something like: [code]$rss_feed = preg_replace('**what goes here?**', '', $rss_feed);[/code]but of course I need the pattern.Thanks in advance if anyone can help.P.S. How might I also strip out all the following tags? [code]<b></b><p></p>[/code]FYI, I looked at this thread ([url=http://www.phpfreaks.com/forums/index.php/topic,99383.0.html]http://www.phpfreaks.com/forums/index.php/topic,99383.0.html[/url]) but it didn't get me the result I wanted... Link to comment https://forums.phpfreaks.com/topic/14650-weeding-out-part-of-an-rss-feed/ Share on other sites More sharing options...
Wildbug Posted July 16, 2006 Share Posted July 16, 2006 [quote author=czheng link=topic=100642.msg397542#msg397542 date=1152937738]... remove from each ITEM everything from (and including) [code]<b>Tags:[/code] up to (but not including) [code]<description>[/code].[/quote]Try this expression:[code]/(<b>Tags:.*?)(?=<description>)/s[/code]The first set of parentheses capture the enclosed expression. The ".*?" construct means "any character, zero or more, ungreedy." The second parenthetical expression is a lookahead assertion, meaning that the regex engine looks for the previous part of the expression, followed by "<description>" without including that in the result.[quote author=czheng link=topic=100642.msg397542#msg397542 date=1152937738]P.S. How might I also strip out all the following tags? [code]<b></b><p></p>[/code][/quote]And this:[code]preg_replace('/<[bp]\/?>/','',$text);[/code] Link to comment https://forums.phpfreaks.com/topic/14650-weeding-out-part-of-an-rss-feed/#findComment-59011 Share on other sites More sharing options...
czheng Posted July 17, 2006 Author Share Posted July 17, 2006 Like a dummy, I didn't pay close enough attention and didn't realize I was going for the CLOSING description tag, not the opening one. The following code works now:[code] $rss_feed = preg_replace("#Tags:(.*?)(?=<\/description>)#", "", $rss_feed);[/code]And I wasn't able to remove the (p) and (b) tags without decoding the HTML. Once I did that, everything was set.Thanks again. Link to comment https://forums.phpfreaks.com/topic/14650-weeding-out-part-of-an-rss-feed/#findComment-59623 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.