davefootball123 Posted August 19, 2012 Author Share Posted August 19, 2012 I got it thanks. Loads a lot faster now. Thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/267240-need-help-with-warning-map-php/page/2/#findComment-1370574 Share on other sites More sharing options...
Christian F. Posted August 19, 2012 Share Posted August 19, 2012 You're welcome, glad I could help. Quote Link to comment https://forums.phpfreaks.com/topic/267240-need-help-with-warning-map-php/page/2/#findComment-1370579 Share on other sites More sharing options...
davefootball123 Posted August 19, 2012 Author Share Posted August 19, 2012 Another issue...of course. I tried to make the code have to meet 2 requirements in order to display the image...so I added $search_string2...now I get strpos() expects parameter 3 to be long. <?php function curl_get_contents($url) { // Initiate the curl session $ch = curl_init(); // 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-94_metric_e.html'); $search_string = '<div class="lefttab">Current Conditions</div>'; $search_string2 = 'WINDSOR'; if(strpos($output, $search_string, $search_string2) !== 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">'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/267240-need-help-with-warning-map-php/page/2/#findComment-1370609 Share on other sites More sharing options...
Barand Posted August 19, 2012 Share Posted August 19, 2012 on another tack, using the RSS  $output = curl_get_contents('http://www.weatheroffice.gc.ca/rss/city/on-94_e.xml'); $xml = simplexml_load_string($output); echo $xml->channel->item[0]->title. '<br /><br />';  //=> No watches or warnings in effect, Windsor echo $xml->channel->item[1]->title. '<br /><br />';  //=> Current Conditions: Cloudy, 15.1°C   Quote Link to comment https://forums.phpfreaks.com/topic/267240-need-help-with-warning-map-php/page/2/#findComment-1370644 Share on other sites More sharing options...
Drongo_III Posted August 19, 2012 Share Posted August 19, 2012 Out of interest... Why do you suggest loading the xml using curl first? Is there some advantage to just straight loading it using simplexml_load_file?    on another tack, using the RSS  $output = curl_get_contents('http://www.weatheroffice.gc.ca/rss/city/on-94_e.xml'); $xml = simplexml_load_string($output); echo $xml->channel->item[0]->title. '<br /><br />';  //=> No watches or warnings in effect, Windsor echo $xml->channel->item[1]->title. '<br /><br />';  //=> Current Conditions: Cloudy, 15.1°C Quote Link to comment https://forums.phpfreaks.com/topic/267240-need-help-with-warning-map-php/page/2/#findComment-1370654 Share on other sites More sharing options...
Barand Posted August 19, 2012 Share Posted August 19, 2012 I was just substituting that file for the one in his code, that's all. Quote Link to comment https://forums.phpfreaks.com/topic/267240-need-help-with-warning-map-php/page/2/#findComment-1370681 Share on other sites More sharing options...
davefootball123 Posted August 19, 2012 Author Share Posted August 19, 2012 How would I change the code to that...but still have it so that if there is a warning...show the overlay...if there isnt then dont? Quote Link to comment https://forums.phpfreaks.com/topic/267240-need-help-with-warning-map-php/page/2/#findComment-1370697 Share on other sites More sharing options...
davefootball123 Posted August 19, 2012 Author Share Posted August 19, 2012 OK I pretty well got it http://www.southernontariochasing.ca/ecwarnings.php Only problem is that it takes a bit to load. How would I make the script run every 5 minutes to create the map using cron job? Â Heres the code <?php function curl_get_contents($url) { // Initiate the curl session $ch = curl_init(); // 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/rss/city/on-94_e.xml'); $search_string = 'No watches or warnings in effect'; 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">'; } $output = curl_get_contents('http://www.weatheroffice.gc.ca/rss/city/on-11_e.xml'); $search_string = 'No watches or warnings in effect'; 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/chatham.png" border="0">'; } $output = curl_get_contents('http://www.weatheroffice.gc.ca/rss/city/on-147_e.xml'); $search_string = 'No watches or warnings in effect'; 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/sarnia.png" border="0">'; } $output = curl_get_contents('http://www.weatheroffice.gc.ca/rss/warning/on-137_e.xml'); $search_string = 'No watches or warnings in effect'; 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/london.png" border="0">'; } $output = curl_get_contents('http://www.weatheroffice.gc.ca/rss/warning/on-98_e.xml'); $search_string = 'No watches or warnings in effect'; 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/elgin.png" border="0">'; } $output = curl_get_contents('http://www.weatheroffice.gc.ca/rss/warning/on-42_e.xml'); $search_string = 'No watches or warnings in effect'; 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/haldimand-norfolk.png" border="0">'; } $output = curl_get_contents('http://www.weatheroffice.gc.ca/rss/warning/on-15_e.xml'); $search_string = 'No watches or warnings in effect'; 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/oxford.png" border="0">'; } $output = curl_get_contents('http://www.weatheroffice.gc.ca/rss/warning/on-86_e.xml'); $search_string = 'No watches or warnings in effect'; 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/brant.png" border="0">'; } $output = curl_get_contents('http://www.weatheroffice.gc.ca/rss/warning/on-77_e.xml'); $search_string = 'No watches or warnings in effect'; 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/hamilton.png" border="0">'; } $output = curl_get_contents('http://www.weatheroffice.gc.ca/rss/warning/on-107_e.xml'); $search_string = 'No watches or warnings in effect'; 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/niagara.png" border="0">'; } $output = curl_get_contents('http://www.weatheroffice.gc.ca/rss/warning/on-82_e.xml'); $search_string = 'No watches or warnings in effect'; 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/waterloo.png" border="0">'; } $output = curl_get_contents('http://www.weatheroffice.gc.ca/rss/warning/on-68_e.xml'); $search_string = 'No watches or warnings in effect'; 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/halton-peel.png" border="0">'; } $output = curl_get_contents('http://www.weatheroffice.gc.ca/rss/warning/on-5_e.xml'); $search_string = 'No watches or warnings in effect'; 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/wellington.png" border="0">'; } $output = curl_get_contents('http://www.weatheroffice.gc.ca/rss/warning/on-143_e.xml'); $search_string = 'No watches or warnings in effect'; 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/toronto.png" border="0">'; } $output = curl_get_contents('http://www.weatheroffice.gc.ca/rss/warning/on-160_e.xml'); $search_string = 'No watches or warnings in effect'; 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/huron.png" border="0">'; } $output = curl_get_contents('http://www.weatheroffice.gc.ca/rss/warning/on-116_e.xml'); $search_string = 'No watches or warnings in effect'; 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/perth.png" border="0">'; } $output = curl_get_contents('http://www.weatheroffice.gc.ca/rss/warning/on-28_e.xml'); $search_string = 'No watches or warnings in effect'; 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/southernbruce.png" border="0">'; } $output = curl_get_contents('http://www.weatheroffice.gc.ca/rss/warning/on-157_e.xml'); $search_string = 'No watches or warnings in effect'; 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/northernbruce.png" border="0">'; } $output = curl_get_contents('http://www.weatheroffice.gc.ca/rss/warning/on-7_e.xml'); $search_string = 'No watches or warnings in effect'; 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/grey.png" border="0">'; } $output = curl_get_contents('http://www.weatheroffice.gc.ca/rss/warning/on-140_e.xml'); $search_string = 'No watches or warnings in effect'; 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/dufferin-innisfil.png" border="0">'; } $output = curl_get_contents('http://www.weatheroffice.gc.ca/rss/warning/on-151_e.xml'); $search_string = 'No watches or warnings in effect'; 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/barrie.png" border="0">'; } $output = curl_get_contents('http://www.weatheroffice.gc.ca/rss/warning/on-64_e.xml'); $search_string = 'No watches or warnings in effect'; 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/york-durham.png" border="0">'; } $output = curl_get_contents('http://www.weatheroffice.gc.ca/rss/warning/on-168_e.xml'); $search_string = 'No watches or warnings in effect'; 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/kawartha.png" border="0">'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/267240-need-help-with-warning-map-php/page/2/#findComment-1370709 Share on other sites More sharing options...
davefootball123 Posted August 19, 2012 Author Share Posted August 19, 2012 Is it also possible to have all those images flatten into 1 image? Quote Link to comment https://forums.phpfreaks.com/topic/267240-need-help-with-warning-map-php/page/2/#findComment-1370745 Share on other sites More sharing options...
darkfreaks Posted August 19, 2012 Share Posted August 19, 2012 http://www.siteground.com/tutorials/cpanel/cron_jobs.htm  also an idea you can array the files then use CURL to fetch them as described in the tutorial below.  http://www.askapache.com/php/curl-multi-downloads.html  Quote Link to comment https://forums.phpfreaks.com/topic/267240-need-help-with-warning-map-php/page/2/#findComment-1370746 Share on other sites More sharing options...
davefootball123 Posted August 19, 2012 Author Share Posted August 19, 2012 Thanks, I created multiple cronjobs so the script runs every 5 minutes...however when I open up the page...it runs the script again. Quote Link to comment https://forums.phpfreaks.com/topic/267240-need-help-with-warning-map-php/page/2/#findComment-1370747 Share on other sites More sharing options...
darkfreaks Posted August 20, 2012 Share Posted August 20, 2012 sounds like you want to manage the cron more with php then. Â Â Â http://net.tutsplus.com/tutorials/php/managing-cron-jobs-with-php-2/ Â Â hopefully this makes it where it reads and writes the file every five minutes. Quote Link to comment https://forums.phpfreaks.com/topic/267240-need-help-with-warning-map-php/page/2/#findComment-1370752 Share on other sites More sharing options...
Drongo_III Posted August 20, 2012 Share Posted August 20, 2012 Yes you can compact everything to one flat image using GD library - http://php.net/manual/en/book.image.php  It's pretty easy to follow the examples but you're in for a bit of a learning curve nonetheless.   Is it also possible to have all those images flatten into 1 image? Quote Link to comment https://forums.phpfreaks.com/topic/267240-need-help-with-warning-map-php/page/2/#findComment-1370788 Share on other sites More sharing options...
davefootball123 Posted August 22, 2012 Author Share Posted August 22, 2012 I have the map part done...now I need some help with the text part...where I'm completely lost. Heres the link of the text I need to grab http://kamala.cod.edu/Canada/latest.wfcn11.CWTO.html Now, I need to have it so that if TORNADO WARNINGS ISSUED FOR ....or TORNADO WARNING CONTINUED FOR....and then have the specific area...in this case it would be looking for WINDSOR-LEAMINGTON-ESSEX COUNTY....I need it so that if tornado warning issued for/continued for windsor...then get the text...else dont get text. Anyone have any ideas?  Thanks, Dave Quote Link to comment https://forums.phpfreaks.com/topic/267240-need-help-with-warning-map-php/page/2/#findComment-1371309 Share on other sites More sharing options...
davefootball123 Posted August 22, 2012 Author Share Posted August 22, 2012 Sorry just needs to be TORNADO WARNING FOR Quote Link to comment https://forums.phpfreaks.com/topic/267240-need-help-with-warning-map-php/page/2/#findComment-1371317 Share on other sites More sharing options...
davefootball123 Posted August 22, 2012 Author Share Posted August 22, 2012 OK, I've figured out that I will use file_get_contents() ...now I just need to know how to have 2 conditions met...before it will display the text. Example  file_get_contents($url) ...if the link has WINDSOR-LEAMINGTON-ESSEX COUNTY...and...TORNADO WARNING...show the text thats on the page.   Thanks for any help, Dave Quote Link to comment https://forums.phpfreaks.com/topic/267240-need-help-with-warning-map-php/page/2/#findComment-1371440 Share on other sites More sharing options...
Drongo_III Posted August 23, 2012 Share Posted August 23, 2012 Well if you want to find specific strings within your contents then you could use preg_match with a regular expression. e.g.:  $tester = file_get_contents('http://kamala.cod.edu/Canada/latest.wfcn11.CWTO.html'); //$tester contains contents to search $pat = '/TORNADO WARNING/'; // literal pattern to find if(preg_match($pat, $tester, $matches)){ echo "Yup, tornado heading your way kid...get out of there you crazy fool!"; print_r($matches); } else { echo "Nothing Found!"; }   You can pass it an array of matches too so you'll be able to find everything you want in one go.  Hope that helps a bit...  You will probably want to get more sophisticated with the match - i.e. only match place name if it's preceded by a specific bit of text. Otherwise the actualy page might say "tornado warning has been stepped down in WINDSOR" and you're preg match will see the warning text and windsor and start scaring people on your site    I have the map part done...now I need some help with the text part...where I'm completely lost. Heres the link of the text I need to grab http://kamala.cod.edu/Canada/latest.wfcn11.CWTO.html Now, I need to have it so that if TORNADO WARNINGS ISSUED FOR ....or TORNADO WARNING CONTINUED FOR....and then have the specific area...in this case it would be looking for WINDSOR-LEAMINGTON-ESSEX COUNTY....I need it so that if tornado warning issued for/continued for windsor...then get the text...else dont get text. Anyone have any ideas?  Thanks, Dave Quote Link to comment https://forums.phpfreaks.com/topic/267240-need-help-with-warning-map-php/page/2/#findComment-1371824 Share on other sites More sharing options...
davefootball123 Posted August 24, 2012 Author Share Posted August 24, 2012 Thats what im looking for, however Im having trouble with 2 conditions. I need the script to check for TORNADO WARNING ENDED FOR as well as SMITHS FALLS - LANARK - SHARBOT LAKE...and I cant seem to get that. Im trying to make it look for both conditions before showing the text. Any ideas? <?php $tester = file_get_contents('http://kamala.cod.edu/Canada/latest.wfcn11.CWTO.html'); //$tester contains contents to search $pat = '/TORNADO WARNING ENDED FOR:/'; // literal pattern to find $pat2 = '/SMITHS FALLS - LANARK - SHARBOT LAKE/'; if(preg_match($pat, $pat2, $tester)){ echo '<center><img style="position:absolute;left:50%;margin-left:-397px; margin-top:30px" src="/Warningoverlays/TOR Warn/windsor.png" border="0">'; } else { echo ''; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/267240-need-help-with-warning-map-php/page/2/#findComment-1372014 Share on other sites More sharing options...
davefootball123 Posted August 24, 2012 Author Share Posted August 24, 2012 After a little bit of playing around I managed to get somewhere This works decent. If the $city...isnt that value then it wont echo the html however it doesnt matter what $tornado is set to...as long as $city is correct it will always echo...even if its not set to tornado warning. <?php $tester = file_get_contents('http://kamala.cod.edu/Canada/latest.wfcn11.CWTO.html'); //$tester contains contents to search $tornado = 'TORNADO WARNING ENDED FOR:'; $city = 'SMITHS FALLS - LANARK - SHARBOT LAKE'; if(preg_match( "/$tornado|$city/i", $tester ) ){ echo '<center><img style="position:absolute;left:50%;margin-left:-397px; margin-top:30px" src="/Warningoverlays/TOR Warn/windsor.png" border="0">'; } else { echo ''; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/267240-need-help-with-warning-map-php/page/2/#findComment-1372015 Share on other sites More sharing options...
Christian F. Posted August 24, 2012 Share Posted August 24, 2012 The thing about Regular Expressions, is that you're meant to use them to define a pattern you want to search for. It is a highly complex syntax, but it has to be in order to make it possible to generate rules for natural languages. At least without it being longer than the patterns you want to match. Â The string you want to match, constitutes of two parts: A static part, and one part in which you have a selected group which can be matched. The easiest RegExp to match this, would be written like this: $RegExp = '/TORNADO WARNING ENDED FOR:\\s+(SMITHS FALLS|LANARK|SHARBOT LAKE)/'; A quick run down of what it means: /Â Â Â Â Â Â Â Â Â Â Â Â Â Â // Opening delimiter, to tell that whatever's after this is the actual pattern to match TORNADO WARNING ENDED FOR:Â // The static, literal part. \s+Â Â Â Â Â Â Â Â Â Â Â Â // One or more whitespace characters (spaces, tabs, etc). (Â Â Â Â Â Â Â Â Â Â Â Â Â Â // Open a capturing sub group, so that we can store the name of the location. SMITHS FALLSÂ Â Â Â Â Â Â Â // Another string literal. |Â Â Â Â Â Â Â Â Â Â Â Â Â Â // Pipe, means "or". When between two string literals, it matches either the one to the left, or the one to the right. LANARKÂ Â Â Â Â Â Â Â Â Â Â // Another string literal. Because of the pipe preceeding this, it'll only match if the previous string literal didn't match. |Â Â Â Â Â Â Â Â Â Â Â Â Â Â // Another "or", in case either of the two previous string literals doesn't match. SHARBOT LAKEÂ Â Â Â Â Â Â Â // The last string literal. )Â Â Â Â Â Â Â Â Â Â Â Â Â Â // Close the capturing sub group, which contains the "or" operation to whatever is inside of it. /Â Â Â Â Â Â Â Â Â Â Â Â Â Â // Ending delimiter, everything after this is a modifier for the pattern. Â If you want to learn more about RegExps, which I recommend if you're going to use them, then please visit the link I gave in the beginning of this post. Â PS: You also need to check the PHP manual for preg_match (), as you're using the wrong syntax for it. Quote Link to comment https://forums.phpfreaks.com/topic/267240-need-help-with-warning-map-php/page/2/#findComment-1372016 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.