Jump to content

Recommended Posts

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.
Link to comment
https://forums.phpfreaks.com/topic/34325-adding-weather-rss-feed-to-my-site/
Share on other sites

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