suess0r Posted January 15, 2007 Share Posted January 15, 2007 Hi,I'm trying to add a weather RSS feed to my site just with the current weather conditions for the zipcode of the record i'm currently viewing. i have found "feed://rss.weather.com/weather/rss/local/"<zip code> but if you go to the site it's a bunch of information and all I want is the top current weather, so can someone help me just parse out the current weather and temp of this feed? I'm new to adding RSS to my site, so I appreciate the help. Thanks everyone. Quote Link to comment Share on other sites More sharing options...
ShogunWarrior Posted January 15, 2007 Share Posted January 15, 2007 I'd write a Regex for it, I hate dealing with XML parsers. Quote Link to comment Share on other sites More sharing options...
suess0r Posted January 15, 2007 Author Share Posted January 15, 2007 This is gunna sound crazy, but what's a regex? ;x Quote Link to comment Share on other sites More sharing options...
ShogunWarrior Posted January 15, 2007 Share Posted January 15, 2007 It's a pattern that the computer matches against a string.So for instance "0-9" matches a number, "a-zA-Z" matches a upper/lower case letter.Then of course they get very complicated like:"@<(example|example2)(.*?)>[ \n\r]*(?:<!\[CDATA\[)?(.*?)(?:\]\]>)?[ \n\r]*</(?:\1)>@s"I suppose regexes aren't the answer if you haven't had much experience with them, they are quite intricate. Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 15, 2007 Share Posted January 15, 2007 Regular Expression is the official term. Google it and you'll find tons of resources. Quote Link to comment Share on other sites More sharing options...
ShogunWarrior Posted January 15, 2007 Share Posted January 15, 2007 Ah, should have used the full term, thanks. Quote Link to comment Share on other sites More sharing options...
suess0r Posted January 15, 2007 Author Share Posted January 15, 2007 So can you explain either A.) How is Regex the answer to my solution or B.) An alternate way of accomplishing this?? Quote Link to comment Share on other sites More sharing options...
ShogunWarrior Posted January 15, 2007 Share Posted January 15, 2007 Regular Expressions are a solution because XML feeds, if they are properly formed follow a pattern and therefore you can extract data with them.However, the proper way to get the information is to use an XML parser which there is lots of documentation on but is still tricky enough. Quote Link to comment Share on other sites More sharing options...
trq Posted January 15, 2007 Share Posted January 15, 2007 A better solution would be to use an xml parser. Thats exactly what they are made for, and also the reason xml is formatted so well.Take a look at the [url=http://php.net/simplexml]simplexml[/url] extension and come back if you get stuck. Using regex for such a task is rediculous IMO. Quote Link to comment Share on other sites More sharing options...
ShogunWarrior Posted January 16, 2007 Share Posted January 16, 2007 It is the right idea to start the proper way. It's strange since I am a proponent of XML in certain situations such as RSS Feeds and configuration files/documentation can also be structured very nicely with it.However, it is hard to be liberal with what you take in when the XML parser freaks out at the slightest thing.The advantage I have experienced with regexs is higher tolerance, much faster parsing and less overhead. Quote Link to comment Share on other sites More sharing options...
scott212 Posted January 16, 2007 Share Posted January 16, 2007 If your looking into regex as a noob, I would highly suggest Expresso -> it's free and a hell of a tutor/tool Quote Link to comment Share on other sites More sharing options...
effigy Posted January 16, 2007 Share Posted January 16, 2007 I agree with [b]thorpe[/b]: use the right tool for the job. If you don't like a certain parser, give the author feedback and try to find a better one. Also, don't make the mistake of blaming the parser if the input is garbage: notify the site providing the feed. If you've exhausted all of your options and regex is your last alternative, see the links in my signature. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.