Jump to content

Need help with array


davefootball123

Recommended Posts

Hi all. I decided it was time to re do my warning map that I have on my website as it was a very in-efficient way to create the map. I have been trying a few things to determine the quickest and most efficient way to do this however I would like your opinion/help.  I have a special weather statements text file seen here http://feeds.michiganwxsystem.com/EC/CWTO/WOCN11.txt . What I am trying to do is match the locations from an array to that text file to see if a special weather statement is in effect for a given region. I am using a preg_match statement currently however I believe it would be easier if I could have an array with every forecast location in it and have the preg_match statement loop through each location in the array to see if there is a special weather statement in effect. The code I have so far is shown below it works from what I can see, the preg_match is looping through the area and is returning if a special weather statement is in effect. It will echo Special Weather Statement however I have to know which location it is returning that value for. If anyone can point me in the right direction from here that would be greatly appreciated.

 

Thanks, Dave

 

<?php


$sws = @file_get_contents('http://feeds.michiganwxsystem.com/EC/CWTO/WOCN11.txt');


$array = array(
    "CITY OF HAMILTON",
    "WINDSOR - ESSEX - CHATHAM-KENT",
"WINDSOR - LEAMINGTON - ESSEX COUNTY",
"CHATHAM-KENT - RONDEAU PARK",
    "SARNIA - LAMBTON",
"WATFORD - PINERY PARK - EASTERN LAMBTON COUNTY",
"SARNIA - PETROLIA - WESTERN LAMBTON COUNTY");

foreach ($array as $location) {

$warning = preg_match('/[\s\w\-]?SPECIAL WEATHER STATEMENT FOR:[\s\w\-\=NEW=]+('.$location.')/', $sws , $matches );

if(!($matches == NULL))
{
echo "Special Weather Statement";
}


}



?>

Link to comment
https://forums.phpfreaks.com/topic/275480-need-help-with-array/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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