Getting weather report

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
zomgwtfbbq
Forum Newbie
Posts: 2
Joined: Wed Sep 16, 2009 5:32 am

Getting weather report

Post by zomgwtfbbq »

Hello,

I'm trying to get the latest weather report from a website, so when I'm on the move I can see if I'm getting wet or not..:p
Anyways, I've tried lots of patterns already using preg_match_all.. but or I end up getting way too much data or nothing at all.
Yes I kind of suck at it, it's been a while since I last used regexes as well.

I'm trying to get just two parts in the code

Code: Select all

<a href="http://www.site.nl/report/today" title="[b]Report for 15-09-2009 generated at 15:00[/b]" class="weather" target="_blank"><img src="[b]http://www.site.nl/bla/bla/somelocation.jpg[/b]"></a>
Any help would be greatly appreciated... :D
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: Getting weather report

Post by superdezign »

zomgwtfbbq wrote:

Code: Select all

<a href="http://www.site.nl/report/today" title="[b]Report for 15-09-2009 generated at 15:00[/b]" class="weather" target="_blank"><img src="[b]http://www.site.nl/bla/bla/somelocation.jpg[/b]"></a>
If that is the exact HTML, then you could easily use this regex:

Code: Select all

~<a href="http://www.site.nl/report/today" title="[b](.+?)[/b]" class="weather" target="_blank"><img src="[b](.+?)[/b]"></a>~
zomgwtfbbq
Forum Newbie
Posts: 2
Joined: Wed Sep 16, 2009 5:32 am

Re: Getting weather report

Post by zomgwtfbbq »

superdezign wrote:
zomgwtfbbq wrote:

Code: Select all

<a href="http://www.site.nl/report/today" title="[b]Report for 15-09-2009 generated at 15:00[/b]" class="weather" target="_blank"><img src="[b]http://www.site.nl/bla/bla/somelocation.jpg[/b]"></a>
If that is the exact HTML, then you could easily use this regex:

Code: Select all

~<a href="http://www.site.nl/report/today" title="[b](.+?)[/b]" class="weather" target="_blank"><img src="[b](.+?)[/b]"></a>~
Thanks for the fast reply, will try it when I'm home.

Thanks again. :)
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Getting weather report

Post by pickle »

If you're in Canada/US, there is an RSS feed for your weather - which may be easier to parse.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply