Jump to content

Weeding out part of an RSS feed


czheng

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.