Jump to content

Don't quite understand this bit of code . . .


Styles2304

Recommended Posts

I got a chunk of code from effigy and I've been trying to modify it to work with something new and I'm having trouble.

 

Here is the code I'm trying to preg_match_all:

<div id="yw-forecast" >
                        <em>Current conditions as of 9:53 am EDT</em>
                        <h3>Fair</h3>
                        <dl>
                            <dt>Feels Like:<\/dt><dd>67°<\/dd>
                            <dt>Barometer:<\/dt><dd>30.08 in and rising<\/dd>
                            <dt>Humidity:<\/dt><dd>57%<\/dd>
                            <dt>Visibility:<\/dt><dd>10 mi<\/dd>
                            <dt>Dewpoint:<\/dt><dd>51&#176;<\/dd>
                            <dt>Wind:<\/dt><dd>NNW 7 mph<\/dd>
                            <dt>Sunrise:<\/dt><dd>6:22 am<\/dd>
                            <dt>Sunset:</dt><dd>9:19 pm</dd>
                        </dl>
                        <div class="forecast-temp">
                            <h3>67&#176;</h3>
                            <p>High: 78&#176; Low: 55&#176;</p>
                            <ul>

                                  <li>» <a class="action" href="#text">Detailed Forecast</a></li>
                                                                      <li>» <a class=action href="http://weather.yahoo.com/climo/USIN0660_f.html">Records & Averages</A>
                                                                  <li>» <a class=action href="http://us.rd.yahoo.com/evt=37752/*http://widgets.yahoo.com/widgets/yahoo-weather">Get Yahoo! Weather on your desktop</a></li>
                            </ul>
                        </div>

                        <div class="forecast-icon" style="background:url('http://l.yimg.com/us.yimg.com/i/us/nws/weather/gr/34d.png'); _background-image/* */: none; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://l.yimg.com/us.yimg.com/i/us/nws/weather/gr/34d.png', sizingMethod='crop'); "></div>

 

and here's what I'm actually trying to retrieve:

Note: *** = I have no F'n clue how to write the regex to retrieve this section.

$patterns = array(
	'/(?<=weatherTempText">)(?P<feels_like>\d+°)/',
	'/(?<=weatherText">)(?P<current_barometer>***/',
	'/(?<=weatherText">)(?P<current_humidity>\d+%)/',
	'/(?<=weatherText">)(?P<current_visibility>***/',
	'/(?<=weatherText">)(?P<current_dewpoint>***;)/',
	'/(?<=weatherText">)(?P<current_wind>***/',
	'/(?<=weatherText">)(?P<current_temp>***/',
	'/(?<=weatherText">)(?P<current_high>***/',
	'/(?<=weatherText">)(?P<current_low>***/',
	'/(?<=weatherimage">)(?P<current_image>***/',
	);

 

Just to give whoever is looking at this their bearings, "current_image" is "http://l.yimg.com/us.yimg.com/i/us/nws/weather/gr/34d.png" and all of that will stay the same except for the filename (34d.png).

 

So yeah . . . I'm probably biting off WAY more than I can chew because I just can't seem to wrap my brain around regex.

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.