davefootball123 Posted August 25, 2012 Share Posted August 25, 2012 I have my warning map fairly well done. It is a background image and if there is warning for a specific location then that overlay shows. However I would like to make the overlays showing into 1.PNG image if possible. Here's my code <?php ob_start(); $url = 'http://www.weatheroffice.gc.ca/rss/warning/on-94_e.xml'; $search_torwatch = 'TORNADO WATCH IN EFFECT'; $search_svrwatch = 'SEVERE THUNDERSTORM WATCH IN EFFECT'; $search_torwarn = 'TORNADO WARNING IN EFFECT'; $search_svrwarn = 'SEVERE THUNDERSTORM WARNING IN EFFECT'; $file_contents = file_get_contents($url); if(strpos($file_contents, $search_torwarn) !== FALSE){ // There's a watch. echo '<center><img style="position:absolute;left:50%;margin-left:-397px; margin-top:30px" src="/Warningoverlays/TOR Warn/windsor.png" border="0">'; } else if(strpos($file_contents, $search_svrwarn) !== FALSE){ // There's a watch. echo '<center><img style="position:absolute;left:50%;margin-left:-397px; margin-top:30px" src="/Warningoverlays/SVR Warn/windsor.png" border="0">'; } else if(strpos($file_contents, $search_torwatch) !== FALSE){ // There's a watch. echo '<center><img style="position:absolute;left:50%;margin-left:-397px; margin-top:30px" src="/Warningoverlays/TOR Watch/windsor.png" border="0">'; } else if (strpos($file_contents, $search_svrwatch) !== FALSE){ // There's a watch. echo '<center><img style="position:absolute;left:50%;margin-left:-397px; margin-top:30px" src="/Warningoverlays/SVR Watch/windsor.png" border="0">'; } else { echo ''; } $url = 'http://www.weatheroffice.gc.ca/rss/warning/on-147_e.xml'; $search_torwatch = 'TORNADO WATCH IN EFFECT'; $search_svrwatch = 'SEVERE THUNDERSTORM WATCH IN EFFECT'; $search_torwarn = 'TORNADO WARNING IN EFFECT'; $search_svrwarn = 'SEVERE THUNDERSTORM WARNING IN EFFECT'; $file_contents = file_get_contents($url); if(strpos($file_contents, $search_torwarn) !== FALSE){ // There's a watch. echo '<center><img style="position:absolute;left:50%;margin-left:-397px; margin-top:30px" src="/Warningoverlays/TOR Warn/westernlambton.png" border="0">'; } else if(strpos($file_contents, $search_svrwarn) !== FALSE){ // There's a watch. echo '<center><img style="position:absolute;left:50%;margin-left:-397px; margin-top:30px" src="/Warningoverlays/SVR Warn/westernlambton.png" border="0">'; } else if(strpos($file_contents, $search_torwatch) !== FALSE){ // There's a watch. echo '<center><img style="position:absolute;left:50%;margin-left:-397px; margin-top:30px" src="/Warningoverlays/TOR Watch/sarnia.png" border="0">'; } else if (strpos($file_contents, $search_svrwatch) !== FALSE){ // There's a watch. echo '<center><img style="position:absolute;left:50%;margin-left:-397px; margin-top:30px" src="/Warningoverlays/SVR Watch/sarnia.png" border="0">'; } else { echo ''; } $url = 'http://www.weatheroffice.gc.ca/rss/warning/on-46_e.xml'; $search_torwarn = 'TORNADO WARNING IN EFFECT'; $search_svrwarn = 'SEVERE THUNDERSTORM WARNING IN EFFECT'; $file_contents = file_get_contents($url); if(strpos($file_contents, $search_torwarn) !== FALSE){ // There's a watch. echo '<center><img style="position:absolute;left:50%;margin-left:-397px; margin-top:30px" src="/Warningoverlays/TOR Warn/easternlambton.png" border="0">'; } else if(strpos($file_contents, $search_svrwarn) !== FALSE){ // There's a watch. echo '<center><img style="position:absolute;left:50%;margin-left:-397px; margin-top:30px" src="/Warningoverlays/SVR Warn/easternlambton.png" border="0">'; } else { echo ''; } $url = 'http://www.weatheroffice.gc.ca/rss/warning/on-137_e.xml'; $search_torwatch = 'TORNADO WATCH IN EFFECT'; $search_svrwatch = 'SEVERE THUNDERSTORM WATCH IN EFFECT'; $search_torwarn = 'TORNADO WARNING IN EFFECT'; $search_svrwarn = 'SEVERE THUNDERSTORM WARNING IN EFFECT'; $file_contents = file_get_contents($url); if(strpos($file_contents, $search_torwarn) !== FALSE){ // There's a watch. echo '<center><img style="position:absolute;left:50%;margin-left:-397px; margin-top:30px" src="/Warningoverlays/TOR Warn/easternmiddlesex.png" border="0">'; } else if(strpos($file_contents, $search_svrwarn) !== FALSE){ // There's a watch. echo '<center><img style="position:absolute;left:50%;margin-left:-397px; margin-top:30px" src="/Warningoverlays/SVR Warn/easternmiddlesex.png" border="0">'; } else if(strpos($file_contents, $search_torwatch) !== FALSE){ // There's a watch. echo '<center><img style="position:absolute;left:50%;margin-left:-397px; margin-top:30px" src="/Warningoverlays/TOR Watch/london.png" border="0">'; } else if (strpos($file_contents, $search_svrwatch) !== FALSE){ // There's a watch. echo '<center><img style="position:absolute;left:50%;margin-left:-397px; margin-top:30px" src="/Warningoverlays/SVR Watch/london.png" border="0">'; } else { echo ''; } $url = 'http://www.weatheroffice.gc.ca/rss/warning/on-116_e.xml'; $search_torwarn = 'TORNADO WARNING IN EFFECT'; $search_svrwarn = 'SEVERE THUNDERSTORM WARNING IN EFFECT'; $file_contents = file_get_contents($url); if(strpos($file_contents, $search_torwarn) !== FALSE){ // There's a watch. echo '<center><img style="position:absolute;left:50%;margin-left:-397px; margin-top:30px" src="/Warningoverlays/TOR Warn/westernmiddlesex.png" border="0">'; } else if(strpos($file_contents, $search_svrwarn) !== FALSE){ // There's a watch. echo '<center><img style="position:absolute;left:50%;margin-left:-397px; margin-top:30px" src="/Warningoverlays/SVR Warn/westernmiddlesex.png" border="0">'; } else { echo ''; } $url = 'http://www.weatheroffice.gc.ca/rss/warning/on-98_e.xml'; $search_torwatch = 'TORNADO WATCH IN EFFECT'; $search_svrwatch = 'SEVERE THUNDERSTORM WATCH IN EFFECT'; $search_torwarn = 'TORNADO WARNING IN EFFECT'; $search_svrwarn = 'SEVERE THUNDERSTORM WARNING IN EFFECT'; $file_contents = file_get_contents($url); if(strpos($file_contents, $search_torwarn) !== FALSE){ // There's a watch. echo '<center><img style="position:absolute;left:50%;margin-left:-397px; margin-top:30px" src="/Warningoverlays/TOR Warn/easternelgin.png" border="0">'; } else if(strpos($file_contents, $search_svrwarn) !== FALSE){ // There's a watch. echo '<center><img style="position:absolute;left:50%;margin-left:-397px; margin-top:30px" src="/Warningoverlays/SVR Warn/easternelgin.png" border="0">'; } else if(strpos($file_contents, $search_torwatch) !== FALSE){ // There's a watch. echo '<center><img style="position:absolute;left:50%;margin-left:-397px; margin-top:30px" src="/Warningoverlays/TOR Watch/elgin.png" border="0">'; } else if (strpos($file_contents, $search_svrwatch) !== FALSE){ // There's a watch. echo '<center><img style="position:absolute;left:50%;margin-left:-397px; margin-top:30px" src="/Warningoverlays/SVR Watch/elgin.png" border="0">'; } else { echo ''; } $url = 'http://www.weatheroffice.gc.ca/rss/warning/on-172_e.xml'; $search_torwarn = 'TORNADO WARNING IN EFFECT'; $search_svrwarn = 'SEVERE THUNDERSTORM WARNING IN EFFECT'; $file_contents = file_get_contents($url); if(strpos($file_contents, $search_torwarn) !== FALSE){ // There's a watch. echo '<center><img style="position:absolute;left:50%;margin-left:-397px; margin-top:30px" src="/Warningoverlays/TOR Warn/westernelgin.png" border="0">'; } else if(strpos($file_contents, $search_svrwarn) !== FALSE){ // There's a watch. echo '<center><img style="position:absolute;left:50%;margin-left:-397px; margin-top:30px" src="/Warningoverlays/SVR Warn/westernelgin.png" border="0">'; } else { echo ''; } $url = 'http://www.weatheroffice.gc.ca/rss/warning/on-15_e.xml'; $search_torwatch = 'TORNADO WATCH IN EFFECT'; $search_svrwatch = 'SEVERE THUNDERSTORM WATCH IN EFFECT'; $search_torwarn = 'TORNADO WARNING IN EFFECT'; $search_svrwarn = 'SEVERE THUNDERSTORM WARNING IN EFFECT'; $file_contents = file_get_contents($url); if(strpos($file_contents, $search_torwarn) !== FALSE){ // There's a watch. echo '<center><img style="position:absolute;left:50%;margin-left:-397px; margin-top:30px" src="/Warningoverlays/TOR Warn/oxford.png" border="0">'; } else if(strpos($file_contents, $search_svrwarn) !== FALSE){ // There's a watch. echo '<center><img style="position:absolute;left:50%;margin-left:-397px; margin-top:30px" src="/Warningoverlays/SVR Warn/oxford.png" border="0">'; } else if(strpos($file_contents, $search_torwatch) !== FALSE){ // There's a watch. echo '<center><img style="position:absolute;left:50%;margin-left:-397px; margin-top:30px" src="/Warningoverlays/TOR Watch/oxford.png" border="0">'; } else if (strpos($file_contents, $search_svrwatch) !== FALSE){ // There's a watch. echo '<center><img style="position:absolute;left:50%;margin-left:-397px; margin-top:30px" src="/Warningoverlays/SVR Watch/oxford.png" border="0">'; } else { echo ''; } $url = 'http://www.weatheroffice.gc.ca/rss/warning/on-151_e.xml'; $search_torwatch = 'TORNADO WATCH IN EFFECT'; $search_svrwatch = 'SEVERE THUNDERSTORM WATCH IN EFFECT'; $search_torwarn = 'TORNADO WARNING IN EFFECT'; $search_svrwarn = 'SEVERE THUNDERSTORM WARNING IN EFFECT'; $file_contents = file_get_contents($url); if(strpos($file_contents, $search_torwarn) !== FALSE){ // There's a watch. echo '<center><img style="position:absolute;left:50%;margin-left:-397px; margin-top:30px" src="/Warningoverlays/TOR Warn/westernsimcoe.png" border="0">'; } else if(strpos($file_contents, $search_svrwarn) !== FALSE){ // There's a watch. echo '<center><img style="position:absolute;left:50%;margin-left:-397px; margin-top:30px" src="/Warningoverlays/SVR Warn/westernsimcoe.png" border="0">'; } else if(strpos($file_contents, $search_torwatch) !== FALSE){ // There's a watch. echo '<center><img style="position:absolute;left:50%;margin-left:-397px; margin-top:30px" src="/Warningoverlays/TOR Watch/barrie.png" border="0">'; } else if (strpos($file_contents, $search_svrwatch) !== FALSE){ // There's a watch. echo '<center><img style="position:absolute;left:50%;margin-left:-397px; margin-top:30px" src="/Warningoverlays/SVR Watch/barrie.png" border="0">'; } else { echo ''; } $url = 'http://www.weatheroffice.gc.ca/rss/warning/on-169_e.xml'; $search_torwarn = 'SEVERE THUNDERSTORM WATCH IN EFFECT'; $search_svrwarn = 'SEVERE THUNDERSTORM WARNING IN EFFECT'; $file_contents = file_get_contents($url); if(strpos($file_contents, $search_torwarn) !== FALSE){ // There's a watch. echo '<center><img style="position:absolute;left:50%;margin-left:-397px; margin-top:30px" src="/Warningoverlays/TOR Warn/northernsimcoe.png" border="0">'; } else if(strpos($file_contents, $search_svrwarn) !== FALSE){ // There's a watch. echo '<center><img style="position:absolute;left:50%;margin-left:-397px; margin-top:30px" src="/Warningoverlays/SVR Warn/northernsimcoe.png" border="0">'; } else { echo ''; } $url = 'http://www.weatheroffice.gc.ca/rss/warning/on-49_e.xml'; $search_torwarn = 'TORNADO WARNING IN EFFECT'; $search_svrwarn = 'SEVERE THUNDERSTORM WARNING IN EFFECT'; $file_contents = file_get_contents($url); if(strpos($file_contents, $search_torwarn) !== FALSE){ // There's a watch. echo '<center><img style="position:absolute;left:50%;margin-left:-397px; margin-top:30px" src="/Warningoverlays/TOR Warn/southernsimcoe.png" border="0">'; } else if(strpos($file_contents, $search_svrwarn) !== FALSE){ // There's a watch. echo '<center><img style="position:absolute;left:50%;margin-left:-397px; margin-top:30px" src="/Warningoverlays/SVR Warn/southernsimcoe.png" border="0">'; } else { echo ''; } $url = 'http://www.weatheroffice.gc.ca/rss/warning/on-13_e.xml'; $search_torwarn = 'TORNADO WARNING IN EFFECT'; $search_svrwarn = 'SEVERE THUNDERSTORM WARNING IN EFFECT'; $file_contents = file_get_contents($url); if(strpos($file_contents, $search_torwarn) !== FALSE){ // There's a watch. echo '<center><img style="position:absolute;left:50%;margin-left:-397px; margin-top:30px" src="/Warningoverlays/TOR Warn/easternsimcoe.png" border="0">'; } else if(strpos($file_contents, $search_svrwarn) !== FALSE){ // There's a watch. echo '<center><img style="position:absolute;left:50%;margin-left:-397px; margin-top:30px" src="/Warningoverlays/SVR Warn/easternsimcoe.png" border="0">'; } else { echo ''; } $page = ob_get_contents(); ob_end_flush(); $fp = fopen("ecwarnings.php","w"); $fp1 = fopen("ecwarnings.html","w"); fwrite($fp,$page); fclose($fp); ?> Logged Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 25, 2012 Share Posted August 25, 2012 First of all, you have the same code over and over again - you need to either make it a function, or start using some arrays and loops. Secondly, I don't see any code in there that is attempting to create an image using PHP. What have you tried so far? Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted August 25, 2012 Share Posted August 25, 2012 i agree with the above your code looks messy and cluttered with all the if statements. it would look much neater if you put some of that into a function like this... function getLineWithString($fileName, $str) { $lines = file($fileName); foreach ($lines as $lineNumber => $line) { if (strpos($line, $str) !== false) { return $line; } } return -1; } this should search for the line in the file and return it if it does not equal FALSE. then output the function and echo the correct picture. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.