Jump to content

If condition met PHP


davefootball123

Recommended Posts

I have a php script listed below to check for warnings and if a warning is in effect echo an overlay...Now it goes in order of the severity of the warning from Tornado Warning all the way to Special Weather Statement. I know its not very good code...however it works pretty good except for one thing...if there are multiple warnings...it will show each overlay...is there a way to have it show only the first overlay in the if statement if more than 1 conditions are met? Example, if there is a Tornado Warning and a Severe Thunderstorm Watch for a region...is it possible just to show the first matched one...the Tornado Warning?

 

Thanks for your help, Dave.

 

<?php

$tor = @file_get_contents('http://www.sowx.ca/tortest.txt');
$svr = @file_get_contents('http://www.sowx.ca/svrtest.txt');
$svs = @file_get_contents('http://www.sowx.ca/svstest.txt');
$sws = @file_get_contents('http://feeds.michiganwxsystem.com/EC/CWTO/WOCN11.txt');

$warnarea = array (
  'WINDSOR - LEAMINGTON - ESSEX COUNTY' => 'windsor',
  'CHATHAM-KENT - RONDEAU PARK' => 'chatham',
  'WINDSOR - ESSEX - CHATHAM-KENT' => 'windsorchatham',
  'SARNIA - PETROLIA - WESTERN LAMBTON COUNTY' => 'westernlambton',
  'WATFORD - PINERY PARK - EASTERN LAMBTON COUNTY' => 'easternlambton',
  'SARNIA - LAMBTON' => 'lambton',
  'STRATHROY - KOMOKA - WESTERN MIDDLESEX COUNTY' => 'westernmiddlesex',
  'LONDON - PARKHILL - EASTERN MIDDLESEX COUNTY' => 'easternmiddlesex',
  'LONDON - MIDDLESEX' => 'middlesex',
  'RODNEY - SHEDDEN - WESTERN ELGIN COUNTY ' => 'westernelgin',
  'ST. THOMAS - AYLMER - EASTERN ELGIN COUNTY' =>  'easternelgin',
  'ELGIN' => 'elgin',
  'SIMCOE - DELHI - NORFOLK' => 'norfolk',
  'DUNNVILLE - CALEDONIA - HALDIMAND' => 'haldimand',
  'ST. CATHARINES - GRIMSBY - NORTHERN NIAGARA REGION' => 'northernniagara',
  'NIAGARA FALLS - WELLAND - SOUTHERN NIAGARA REGION' => 'southernniagara',
  'NIAGARA' => 'niagara',
  'CITY OF HAMILTON' => 'hamilton',
  'BRANTFORD - COUNTY OF BRANT' => 'brant',
  'WOODSTOCK - TILLSONBURG - OXFORD COUNTY' => 'oxford',
  'OXFORD - BRANT' => 'oxfordbrant',
  'CALEDON' => 'northernpeel',
  'CITY OF TORONTO' => 'toronto',
  'MISSISSAUGA - BRAMPTON' => 'southernpeel',
  'HALTON HILLS - MILTON' => 'northernhalton',
  'BURLINGTON - OAKVILLE' => 'southernhalton',
  'HALTON - PEEL' => 'haltonpeel',
  'WATERLOO - WELLINGTON' => 'waterloowellington',
  'KITCHENER - CAMBRIDGE - REGION OF WATERLOO' => 'waterloo',
  'GUELPH - ERIN - SOUTHERN WELLINGTON COUNTY' => 'southernwellington',
  'MOUNT FOREST - ARTHUR - NORTHERN WELLINGTON COUNTY' => 'northernwellington',
  'HURON - PERTH' => 'huronperth',
  'WINGHAM - BLYTH - NORTHERN HURON COUNTY' => 'northernhuron',
  'LISTOWEL - MILVERTON - NORTHERN PERTH COUNTY' => 'northernperth',
  'GODERICH - BLUEWATER - SOUTHERN HURON COUNTY' => 'southernhuron',
  'STRATFORD - MITCHELL - SOUTHERN PERTH COUNTY' => 'southernperth',
  'GREY - BRUCE' => 'greybruce',
  'BRUCE PENINSULA - SAUBLE BEACH - TOBERMORY' => 'northernbruce',
  'OWEN SOUND - BLUE MOUNTAINS - NORTHERN GREY COUNTY' => 'northerngrey',
  'SAUGEEN SHORES - KINCARDINE - SOUTHERN BRUCE COUNTY' => 'southernbruce',
  'HANOVER - DUNDALK - SOUTHERN GREY COUNTY' => 'southerngrey',
  'INNISFIL - NEW TECUMSETH - ANGUS' => 'southernsimcoe',
  'SHELBURNE - MANSFIELD - NORTHERN DUFFERIN COUNTY' => 'northerndufferin',
  'ORANGEVILLE - GRAND VALLEY - SOUTHERN DUFFERIN COUNTY' => 'southerndufferin',
  'DUFFERIN - INNISFIL' => 'dufferininnisfil',
  'BARRIE - ORILLIA - MIDLAND' => 'barrieorilliamidland',
  'MIDLAND - COLDWATER - ORR LAKE' => 'northernsimcoe',
  'ORILLIA - LAGOON CITY - WASHAGO' => 'easternsimcoe',
  'BARRIE - COLLINGWOOD - HILLSDALE' => 'westernsimcoe',
  'YORK - DURHAM' => 'yorkdurham',
  'UXBRIDGE - BEAVERTON - NORTHERN DURHAM REGION' => 'northerndurham',
  'NEWMARKET - GEORGINA - NORTHERN YORK REGION' => 'northernyork',
  'PICKERING - OSHAWA - SOUTHERN DURHAM REGION' => 'southerndurham',
  'VAUGHAN - RICHMOND HILL - MARKHAM' => 'southernyork',
  'PETERBOROUGH - KAWARTHA LAKES' => 'peterboroughkawartha',
  'FENELON FALLS - BALSAM LAKE PARK - NORTHERN KAWARTHA LAKES' => 'northernkawartha',
  'LINDSAY - SOUTHERN KAWARTHA LAKES' => 'southernkawartha',
  'APSLEY - WOODVIEW - NORTHERN PETERBOROUGH COUNTY' => 'northernpeterborough',
  'PETERBOROUGH CITY - LAKEFIELD - SOUTHERN PETERBOROUGH COUNTY' => 'southernpeterborough',
  'BELLEVILLE - QUINTE - NORTHUMBERLAND' => 'belleville',
  'BELLEVILLE - QUINTE WEST - EASTERN NORTHUMBERLAND COUNTY' => 'easternnorthumberland',
  'COBOURG - COLBORNE - WESTERN NORTHUMBERLAND COUNTY' => 'westernnorthumberland');





echo '<img style="position:absolute;left:50%;; margin-top:15px" src="/warnings/countieswithbackground.png" border="0">';

foreach ($warnarea as $region => $value) {

if (preg_match('/TORNADO WARNING FOR:[\s\w\-\=NEW=]+'.$region.'/', $tor)) {
echo '<img style="position:absolute;left:50%;; margin-top:15px" src="/WWAMAP/TornadoWarnings/'.$value.'.png" border="0">';

 }
 else if (preg_match('/SEVERE THUNDERSTORM WARNING FOR:[\s\w\-\=NEW=]+'.$region.'/', $svr)) {
echo '<img style="position:absolute;left:50%;; margin-top:15px" src="/WWAMAP/SevereThunderstormWarnings/'.$value.'.png" border="0">';

 }
  else if (preg_match('/BLIZZARD WARNING FOR:[\s\w\-\=NEW=]+'.$region.'/', $svs)) {
echo '<img style="position:absolute;left:50%;; margin-top:15px" src="/WWAMAP/BlizzardWarnings/'.$value.'.png" border="0">';

 }
  else if (preg_match('/WINTER STORM WARNING FOR:[\s\w\-\=NEW=]+'.$region.'/', $svs)) {
echo '<img style="position:absolute;left:50%;; margin-top:15px" src="/WWAMAP/WinterstormWarnings/'.$value.'.png" border="0">';

 }
  else if (preg_match('/SNOW SQUALL WARNING FOR:[\s\w\-\=NEW=]+'.$region.'/', $svs)) {
echo '<img style="position:absolute;left:50%;; margin-top:15px" src="/WWAMAP/SnowsquallWarnings/'.$value.'.png" border="0">';

 }
  else if (preg_match('/BLOWING SNOW WARNING FOR:[\s\w\-\=NEW=]+'.$region.'/', $svs)) {
echo '<img style="position:absolute;left:50%;; margin-top:15px" src="/WWAMAP/BlowingsnowWarnings/'.$value.'.png" border="0">';

 }
  else if (preg_match('/WIND WARNING FOR:[\s\w\-\=NEW=]+'.$region.'/', $svs)) {
echo '<img style="position:absolute;left:50%;; margin-top:15px" src="/WWAMAP/WindWarnings/'.$value.'.png" border="0">';

 }
 else if (preg_match('/WIND CHILL WARNING FOR:[\s\w\-\=NEW=]+'.$region.'/', $svs)) {
echo '<img style="position:absolute;left:50%;; margin-top:15px" src="/WWAMAP/WindchillWarnings/'.$value.'.png" border="0">';

 }
  else if (preg_match('/SNOWFALL WARNING FOR:[\s\w\-\=NEW=]+'.$region.'/', $svs)) {
echo '<img style="position:absolute;left:50%;; margin-top:15px" src="/WWAMAP/SnowfallWarnings/'.$value.'.png" border="0">';

 }
  else if (preg_match('/FREEZING RAIN WARNING FOR:[\s\w\-\=NEW=]+'.$region.'/', $svs)) {

echo '<img style="position:absolute;left:50%;; margin-top:15px" src="/WWAMAP/FreezingrainWarnings/'.$value.'.png" border="0">';

 }
  else if (preg_match('/FLASH FREEZE WARNING FOR:[\s\w\-\=NEW=]+'.$region.'/', $svs)) {
echo '<img style="position:absolute;left:50%;; margin-top:15px" src="/WWAMAP/FlashfreezeWarnings/'.$value.'.png" border="0">';

 }
   else if (preg_match('/FREEZING DRIZZLE WARNING FOR:[\s\w\-\=NEW=]+'.$region.'/', $svs)) {
echo '<img style="position:absolute;left:50%;; margin-top:15px" src="/WWAMAP/FreezingdrizzleWarnings/'.$value.'.png" border="0">';

 }
   else if (preg_match('/RAINFALL WARNING FOR:[\s\w\-\=NEW=]+'.$region.'/', $svs)) {
echo '<img style="position:absolute;left:50%;; margin-top:15px" src="/WWAMAP/RainfallWarnings/'.$value.'.png" border="0">';

 }
   else if (preg_match('/COLD WAVE WARNING FOR:[\s\w\-\=NEW=]+'.$region.'/', $svs)) {
echo '<img style="position:absolute;left:50%;; margin-top:15px" src="/WWAMAP/ColdwaveWarnings/'.$value.'.png" border="0">';

 }
     else if (preg_match('/FROST WARNING FOR:[\s\w\-\=NEW=]+'.$region.'/', $svs)) {
echo '<img style="position:absolute;left:50%;; margin-top:15px" src="/WWAMAP/FrostWarnings/'.$value.'.png" border="0">';

 }
       else if (preg_match('/WEATHER WARNING FOR:[\s\w\-\=NEW=]+'.$region.'/', $svs)) {
echo '<img style="position:absolute;left:50%;; margin-top:15px" src="/WWAMAP/WeatherWarnings/'.$value.'.png" border="0">';

 }
    else if (preg_match('/TORNADO WATCH FOR:[\s\w\-\=NEW=]+'.$region.'/', $svs)) {
echo '<img style="position:absolute;left:50%;; margin-top:15px" src="/WWAMAP/TornadoWatches/'.$value.'.png" border="0">';

 }
       else if (preg_match('/SEVERE THUNDERSTORM WATCH FOR:[\s\w\-\=NEW=]+'.$region.'/', $svs)) {
echo '<img style="position:absolute;left:50%;; margin-top:15px" src="/WWAMAP/SevereThunderstormWatches/'.$value.'.png" border="0">';

 }
          else if (preg_match('/WINTER STORM WATCH FOR:[\s\w\-\=NEW=]+'.$region.'/', $svs)) {
echo '<img style="position:absolute;left:50%;; margin-top:15px" src="/WWAMAP/WinterstormWatches/'.$value.'.png" border="0">';

 }
          else if (preg_match('/SNOW SQUALL WATCH FOR:[\s\w\-\=NEW=]+'.$region.'/', $svs)) {
echo '<img style="position:absolute;left:50%;; margin-top:15px" src="/WWAMAP/SnowsquallWatches/'.$value.'.png" border="0">';

 }
          else if (preg_match('/SPECIAL WEATHER STATEMENT:[\s\w\-\=NEW=]+'.$region.'/', $sws)) {
echo '<img style="position:absolute;left:50%;; margin-top:15px" src="/WWAMAP/SpecialWeatherStatements/'.$value.'.png" border="0">';
 }

   
}
echo '<img style="position:absolute;left:50%;; margin-top:15px" src="/warnings/highways.png" border="0">';
echo '<img style="position:absolute;left:50%;; margin-top:15px" src="/warnings/cities.png" border="0">';


?>

 

Link to comment
https://forums.phpfreaks.com/topic/276308-if-condition-met-php/
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.