Jump to content

michael.davis

Members
  • Posts

    61
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

michael.davis's Achievements

Member

Member (2/5)

0

Reputation

  1. 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";
  2. 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
  3. Hi Everyone! Getting this error code with my php script that I am using. Deprecated: Function ereg() is deprecated Was working fine and now it is not. <?php chdir(dirname(__FILE__)); $dir = "/sync/www/html/ohx/training"; $numberOfFiles = 6; $pattern = '\.(pdf|xlsx|xls|doc|docx)$'; $newstamp = 0; $newname = ""; $dc = opendir($dir); unset($fils); while ($fn = readdir($dc)) { # Eliminate current directory, parent directory if (ereg('^\.{1,2}$',$fn)) continue; # Eliminate other pages not in pattern if (! ereg($pattern,$fn)) continue; //echo "<a href='$fn'>$fn</a><br>\n"; $timedat = filemtime("$dir/$fn"); //$fils["a" . $timedat . "$fn"] = $fn;//keep file name and time so if 2 files have same time they dont get lost $fils[$fn] = $timedat;//keep file name and time so if 2 files have same time they dont get lost /*if ($timedat > $newstamp) { $newstamp = $timedat; $newname = $fn; } */ } ksort ($fils, SORT_NUMERIC); //for($i = 0; $i < $numberOfFiles ; $i++) $fils2 = array_keys($fils); $i = 0; foreach($fils2 as $s){ $i++; echo "<a href=training/$s>$s</a><br>\n"; //echo "$i " . $s . "<br>\n"; if($i == $numberOfFiles )break; } ?>
  4. Ok I just edited the code and can get the 24 hour data. <?php //$xml = new SimpleXML $xml = SimpleXML_load_file('http://www.amecim.com/metronashvillewater/metronashvilleraingaugeservice.asmx/getAllGaugesAllIntervals'); $firstChildrenArray = array(); // going to hold parent elements $secondChildArray = array(); // going to hold child elements of each clsRainGaugeReading foreach($xml->children() as $child) { $firstChildrenArray[] = $child->getName(); } foreach($firstChildrenArray as $v){ foreach($xml->{$v}->TwentyfourHour as $vv){ $secondChildArray[] = get_object_vars($vv); } } echo "<pre>"; // get rid of this line print_r($secondChildArray); // just to demonstrate end result echo "" . $secondChildArray[3]['GaugeName'] ; ?>
  5. http://www.amecim.com/metronashvillewater/metronashvilleraingaugeservice.asmx/getAllGaugesAllIntervals The file above has 15 min, 30 minute, 1 hour, 2 hour, 4 hour, 6 hour and 24 values in this file. The USGS prefers we source this to gather all intervals and data associated with that interval that we require. This is really nice as it will be a one sources, yet the php code that we are working on slightly changes. Could use some help. Thanks! Mike
  6. Hi Drongo_III! That is exactly what I needed. Thanks!!!!
  7. Thanks for your help Drongo_III! What I am trying to do is pull in the data and format it in a line format to be ingested into our database. What I would like to do is put the site and related data into one line at a time. Fore example: SITE DATE TIME VALUE BntCrk : 82712 DH1640/0 Does that make sense? Thanks! Mike
  8. So to break it out into two different arrays will work best? Make sense. Ok...brain dump here. I believe my brain is fried now. To list the matching first array item with the first array data fields, I need to add? Thanks for your help! Mike
  9. Interesting. I used the SimpleXMLElement in a previous script and works fine.
  10. Good Monday Everyone! I am working on some code to pull in an XML formatted page from the internet and break it out into variables. I am not sure what I am missing here, but it will not parse the data. I am sure something simple. Here is the web link: http://www.amecim.com/metronashvillewater/metronashvilleraingaugeservice.asmx/getAllGauges15m Listed below is the code: <?php // // 15 Minute Gauge Data // $xml = new SimpleXMLElement('http://www.amecim.com/metronashvillewater/metronashvilleraingaugeservice.asmx/getAllGauges15m', 0, true); foreach ($xml->clsRainGaugeReading as $row) { printf("Sample Date: %s\n", $row->SampleDate); echo "<br>"; printf("Sample Time: %s\n", $row->SampleTime); echo "<br>"; printf("Gauge Name: %u\n", $row->GaugeName); echo "<br>"; printf("Sample Value: %u\n", $row->SampleValue); echo "<br>"; echo "<br>"; } ?> Thanks in advance for any help. Mike
  11. Thank you for the help! I was trying my darnest to display just that one line, then to get explode to work. Thank you!
  12. This link is better for what I am doing: http://www.srh.noaa.gov/productview.php?pil=OHXRWRMEG
  13. Understand. Nashville is used once. The City name stays the same length but the data in the other columns besides the city name are not fixed . Using the explode function should work. Does the explode function only used fixed spaces or will explode adjust for the white spacing differences?
  14. Looking to the explode function. Thanks! Just not sure how to grab just that one line.
×
×
  • 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.