Blocking part of an RSS feed

Discussion in 'Web Design and Development' started by kwarren, Jan 26, 2009.

  1. kwarren Guest

    Joined:
    Aug 18, 2007
    #1
    Hi,

    I am currently pulling an RSS feed, but it's a Twitter feed, so each story looks like "username: _____". As you can imagine, this gets a bit tedious when you're viewing a list of stories.

    Is there any way to "block" or "cut" the first x number of characters from an RSS feed?

    Thanks,

    EDIT: Here's an example of what I mean
    feed://twitter.com/statuses/user_timeline/6351572.rss

    Just cut off the username so that it immediately shows the tweet
     
  2. SrWebDeveloper macrumors 68000

    SrWebDeveloper

    Joined:
    Dec 7, 2007
    Location:
    Alexandria, VA, USA
    #2
    First, see if there is an option to remove keywords in a channel title or description via GUI or configuration. If not, then the code will have to be hacked (which might not be easy) as follows:

    Taking into account PhillyD might change their username, you don't want to just cut the first X letters or look for that specific name, you instead would likely use a regular expression which identifies the name from the first letter of the channel feed title up to the first colon and space and then cut it out (replace with nothing). Looking at the actual feed, that same username also shows up in the feed title, feed description and feed channel description so you'd surely want to cut those as well, right? Doing it this way, it doesn't matter what the username is, so long as it appears in that position in the channel title.

    Yes, you could simply replace any static instance "PhillyD" and "PhillyD:" as well, so long as the feed NEVER changes in regard to that username. That's up to you.

    But to help you at all we obviously need your code to turn these concepts into reality. You will also need to tell us which of the four instances of the username, or if all, should be cut.


    -jim
     
  3. kwarren thread starter Guest

    Joined:
    Aug 18, 2007
    #3
    Hi Jim,

    Yes, blocking from the first letter until the first colon seems like the best option when you take into account the possibility of username change.

    The problem, though, is that I'm currently using FeedBurner to pull the RSS feed due to some very odd, complicated circumstances. Does anyone have experience working with/modifying FeedBurner code or is there a better way? I've turned to FeedBurner because I needed a simple way to pull from an RSS feeder in my iPhone app, and it seemed like the best option

    Thanks again,
     
  4. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #4
    Can you elaborate on your code for pulling it in and such? Are you using PHP, JavaScript, etc. I can do some nifty stuff using regular expressions to eliminate unwanted text, but would need to know how you're doing things currently to have a clue where to start.
     
  5. TodVader macrumors 6502a

    TodVader

    Joined:
    Sep 27, 2005
    Location:
    Quebec, Canada
    #5
    If you know what characters you want to delete, you could do a str_replace to replace the string with "".
    I just did so here while messing arround with eBay feeds:
    http://dev.vhs-movies.net/

    This is a feed from eBay that had lots of unwanted stuff in it.

    You can parse RSS feeds to a html page with PHP. It isn't too complicated.
     
  6. kwarren thread starter Guest

    Joined:
    Aug 18, 2007
    #6
    Wow, angel, thanks for the help!

    As far as I can tell, FeedBurner uses XML. However, as I said, I'm running this feed in my iPhone app using UITableView, so perhaps that is the better way to go? I posted in here because, well, you guys seem nicer to the idiots and definitely know your stuff.

    Thanks again!
     
  7. SrWebDeveloper macrumors 68000

    SrWebDeveloper

    Joined:
    Dec 7, 2007
    Location:
    Alexandria, VA, USA
    #7
    Which is why I specifically said to the OP:

    This isn't doing it right, for the reason stated. I advised the user that the better way is to do the search/replace using pattern matching and modify the original source so nothing else needs to change in the website. FYI, but thanks for contributing.

    -jim
     
  8. kwarren thread starter Guest

    Joined:
    Aug 18, 2007
    #8
    Hi Jim,

    You seem to have thought this method out; is there any way you can provide idiot-proof instructions for me?

    Thanks!
     
  9. SrWebDeveloper macrumors 68000

    SrWebDeveloper

    Joined:
    Dec 7, 2007
    Location:
    Alexandria, VA, USA
    #9
    To OP:

    If you mean the Feedburner recently aquired by Google, I took a look and it's web based system and proprietary, no way to change "it" in terms of code. However, I clicked on the developer link and they have an API for accessing feeds within the Feedburner system and you can easily pull/change any element of the feed (title, description of channels, etc.).

    Check out this page for the developer guide and their API

    This is a PHP class written by someone else to access the Feedburner API - this class seems to handle what you need to do. Examine that code and modify it to do what you want (i.e. add a set method to determine a keyword to replace in the feed, add a private method to do the task)

    A professional solution, and completely scalable. This is my advice.

    Anything else is a quick fix, and other users have suggested how to do that already or are willing to help so long as you have the actual XML file of the feed or the HTML version of it to edit. My method does not require that.

    -jim
     
  10. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #10
    It's still not clear how you're working with the XML or if it's something else that's using the XML, but here's a basic regular expression to handle a given string in the form you mentioned using PHP.

    PHP:
    $str "username: _____";
    $str preg_replace('/(.*: )/'""$str);
    // result: _____
     

Share This Page