Jump to content

Recommended Posts

Happy Monday Everyone! I hope you all had a great weekend!

 

I have a script that usually runs just fine, however, I ran into an issue today. We are having light rain, this my code below is not working due to the $match[1] field is not one word, it is two words. If I change the $city to a condition that is one word, then it works fine. I know it is something simple and hope someone can help me with it.

 

 

 


<?php

$data = file_get_contents('http://www.srh.noaa.gov/productview.php?pil=OHXRWROHX') or die("Can't open URL"); $city = 'Nashville';

$expr = "%$city*?\s+ ([a-z/]+)\s+ (n/a|\d+)\s+ (n/a|\d+)\s+ (n/a|\d+)\s+ ([a-z0-9]+)\s+ (n/a|[0-9.]+[a-z])%ix";

preg_match( $expr, $data, $match ); $site = $match[0]; $COND = $match[1]; $TEMP = $match[2]; $DEW = $match[3]; $HUMID = $match[4]; $WIND = $match[5]; $PRES = $match[6];

echo $site;
echo $COND;
echo $$TEMP;
echo $DEW;
echo $HUMID;
echo $WIND;
echo $PRES;
echo $data;
?>

 

The data below is what the script pulls in. The city of Gallatin works fine, but Nashville does not due to the two word in the $COND field.

 

 

562

ASUS44 KOHX 121310

RWROHX

MIDDLE TENNESSEE HOURLY WEATHER ROUNDUP

NATIONAL WEATHER SERVICE NASHVILLE TN

700 AM CST MON NOV 12 2012

 

NOTE: "FAIR" INDICATES FEW OR NO CLOUDS BELOW 12,000 FEET WITH

NO SIGNIFICANT WEATHER AND/OR OBSTRUCTIONS TO VISIBILITY.

 

* THESE REPORTS ARE NOT UNDER NWS QUALITY CONTROL AND MAY NOT

REPORT WEATHER SUCH AS PRECIPITATION AND FOG.

 

 

TNZ005>011-023>034-057-059-062>066-078-080-121400

...NORTHERN MIDDLE TENNESSEE...

 

CITY SKY/WX TMP DP RH WIND PRES REMARKS

ANTIOCH* N/A 52 48 87 W5 N/A

BAXTER* N/A 59 52 77 SE13 N/A

BURNS* N/A N/A N/A N/A W3 N/A

CAMDEN* N/A 50 50 100 W6 N/A

CELINA* N/A 61 59 94 SW8 N/A

CLARKSVILLE LGT RAIN 52 50 93 NW9 30.16R FOG

COLUMBIA CLOUDY 55 55 100 NW8 30.15R

CROSSVILLE CLOUDY 59 54 83 S12G22 30.21R

GALLATIN CLOUDY 57 57 100 SW8 30.14R

DICKSON CLOUDY 50 48 93 W7 30.16R

DOVER* N/A 52 50 93 W1 N/A

GOODLETTSVILLE N/A 59 52 77 CALM N/A

HERMITAGE* N/A 57 55 94 MISG N/A

KINGSTON SPGS* N/A 54 52 94 CALM N/A

LAFAYETTE* N/A 57 57 100 SW7 N/A

LEBANON CLOUDY 57 57 100 SW8 30.12R

LIVINGSTON CLOUDY 58 54 86 S15 30.12S

MOUNT JULIET* N/A N/A N/A N/A CALM N/A

NASHVILLE LGT RAIN 57 55 94 SW8 30.14R FOG

OLD HICKORY* N/A 59 59 100 W3 N/A

PEGRAM* N/A N/A N/A N/A W3 N/A

PORTLAND CLOUDY 55 55 100 SW13 30.12R

SMYRNA LGT RAIN 57 57 100 SW5 30.16R FOG

WAVERLY* N/A 52 48 87 W5 N/A

WHITE BLUFF* N/A 54 50 87 MISG N/A

$$

TNZ056-058-060-061-075>077-079-093>097-121400

...SOUTHERN MIDDLE TENNESSEE...

 

CITY SKY/WX TMP DP RH WIND PRES REMARKS

ALTAMONT* N/A 57 55 94 S5 N/A

BELLEVUE* N/A 55 54 94 CALM N/A

CHAPEL HILL* N/A 57 55 94 SW2 N/A

CULLEOKA* N/A 57 57 100 S3 N/A

EAGLEVILLE* N/A N/A N/A N/A W3 N/A

FAIRVIEW* N/A 52 52 100 W1 N/A

FAYETTEVILLE CLOUDY 57 56 97 S10 30.15R

LEWISBURG CLOUDY 57 55 94 S5 30.14R

MANCHESTER* N/A 59 57 94 S6G20 N/A

MCMINNVILLE MOCLDY 59 56 89 S12 30.14S

MOUNT PLEASANT N/A 55 54 94 CALM N/A

MURFREESBORO CLOUDY 59 58 96 SW5 30.13R

SHELBYVILLE CLOUDY 57 55 94 S12 30.15

SHELBYVILLE* N/A 61 59 94 SW8 N/A

SPRING HILL* N/A 59 55 88 NE5 N/A

THOMPSON STN* N/A 57 55 94 W3 N/A

TULLAHOMA MOCLDY 57 55 94 S13 30.16R

WINCHESTER CLOUDY 59 55 88 SE6 30.15F

$$

 

 

...KEY TO REMARKS...

VSB - VISIBILITY IN MILES

WCI - WIND CHILL INDEX

HX - HEAT INDEX

 

Thanks!

Mike

Link to comment
https://forums.phpfreaks.com/topic/270596-php-expr-issue/
Share on other sites

I guess what I am trying to ask is what is the code format to look at not only one word but two words like Cloudy and LGT RAIN in one field like it is below: ([a-z/]+)\s+

 

 

$expr = "%$city*?\s+ ([a-z/]+)\s+ (n/a|\d+)\s+ (n/a|\d+)\s+ (n/a|\d+)\s+ ([a-z0-9]+)\s+ (n/a|[0-9.]+[a-z])%ix";

Link to comment
https://forums.phpfreaks.com/topic/270596-php-expr-issue/#findComment-1391856
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.