Jump to content

Need help with warning map. PHP


davefootball123

Recommended Posts

Hi everyone. I'm coding an Environment Canada weather warning map for better ease of use for people. What I need is hopefully simple. On the EC website if a warning is issued a text bulliten for the forecast page will say SEVERE THUNDERSTORM WARNING or any type of warning for that matter. Here is an example of the page http://www.weatheroffice.gc.ca/city/pages/on-94_metric_e.html , if a severe thunderstorm warning is issued at the top of the page it will say SEVERE THUNDERSTORM WARNING IN EFFECT, or TORNADO WARNING IN EFFECT for a tornado warning. What I need to do is have a php code check that url and see if SEVERE THUNDERSTORM WARNING exists and it if does show an image...just a normal <img src="file name"> image.

I hope i explained it clear enough. I think what I need is for php to read the content of an external url and if the required content exists...show the image...if not dont show the image. If anyone could help me that would be greatly appreciated. Thanks, Dave

Link to comment
Share on other sites

<?php

$url = 'http://www.southernontariochasing.ca/testwarn.html';

$search_string = 'SEVERE THUNDERSTORM WARNING IN EFFECT';

$file_contents = file_get_contents($url);

if(stripos($file_contents, $search_string) !== FALSE){

// There's a warning.

echo '<img src="Day 1 Cat.png" />';

}

?>

 

Works great. Thanks!

If I have another issue I will be sure to come back. You guys are great!

Link to comment
Share on other sites

To follow up to my last post...heres a quick example of what im doing http://www.southernontariochasing.ca/test.php

 

Works wonderful. Thank you.

 

EDIT: One other quick thing. the website that is being read displays the data as <a herf="link>SEVERE THUNDERSTORM WARNING</a> and I have to put that full html code in the seach_string...works fine however the link changes with the issuance of each weather warning. Is there anyway to get around that?

 

Sorry to edit again. I have seem'd to figure it out. Thanks for all the help!

Link to comment
Share on other sites

I think this page will be a good starting point for you, especially if you read the user notes as well. I also recommend reading some tutorials on how to write PHP, the one in the PHP manual is a good start.

Programming is pure logic, after all. So if you've done something that works before, and want to do something just a bit differently, chances are you just have to change the part that's different.

Link to comment
Share on other sites

OK, I've done a little bit of work, however I continue to have some issues. I believe I changed to cURL properly...however I think strpos is having some trouble reading $search_string because when the condition is met...the overlay doesnt show up. When I set the ! == TRUE...the overlays will always show up. If i set it to false the overlays never show up even when they should.

Here is the code

<?php
$url = 'http://www.weatheroffice.gc.ca/city/pages/on-147_metric_e.html';
function curl_get_contents($url) {
// Initiate the curl session
$ch = curl_init('http://www.weatheroffice.gc.ca/city/pages/on-147_metric_e.html');
// Set the URL<span id="more-487"></span>
curl_setopt($ch, CURLOPT_URL, $url);
// Removes the headers from the output
curl_setopt($ch, CURLOPT_HEADER, 0);
// Return the output instead of displaying it directly
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// Execute the curl session
$output = curl_exec($ch);
// Close the curl session
curl_close($ch);
// Return the output as a variable
return $output;
}

$output = curl_get_contents('http://www.weatheroffice.gc.ca/city/pages/on-147_metric_e.html');
$search_string = 'SEVERE THUNDERSTORM WATCH IN EFFECT</a>';


if(strpos($output, $search_string) !== 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">';
}

?>

Link to comment
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.