Jump to content

Archived

This topic is now archived and is closed to further replies.

czheng

Weeding out part of an RSS feed

Recommended Posts

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...

Share this post


Link to post
Share on other sites
[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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.