PHP Tide Clock

Here’s a quick little script for predicting tides. Be sure and change the high tide time on line 2. You may have to play around with the numbers a little to get it working on your site. Please, don’t ever use this script for navigational purposes. Seriously, this is a rough estimate and not for marine navigation purposes.

Tides depend on many factors, sun, moon, wind and some other things I don’t understand. But I do understand tides differ by a set amount of time in most places – usually. I developed this code to work for Folly Beach, but it will work in locations with a 12:50 time difference between high tides. As a general rule, this works fairly well, but you will still need to update the tides occasionally or during time changes.

<!–
php tide by dawhoo
*********************************************************************
© dawhoo 2004
dawhoo.com
This script must be used in whole with credit in tact.
php tide script by philip nicholson

*********************************************************************
do not rely on this script for navigational purposes – serious
*********************************************************************

Instructions:
Paste into any php page an viola! There are the predicted next tides.
1)Change $knowntide to the last observed high tide
2)You may need to tweak the $knowntide to adjust for a server in a different time zone than where the tides are being measured.
–>

<?php
$knowntide = strtotime(’2007-06-25 18:30′); // known hightide use the sample format
$current = date(U);
$interval = (12 * 3600) + (25 * 60);
// 12 hours and 50 minutes between high tides
$num_tides_passed = floor(($current – $knowntide) / $interval);
$last_tide = $knowntide + ($interval * $num_tides_passed);
$next_high = $last_tide + (12 * 3600) + (25 * 60);
// 12 hours and 50 minutes between 2 high tides
$next_low = $last_tide + (6 * 3600) + (13 * 60); ?> // 6 hours and 13 minutes between high and low

<?php echo date(’m/d g:i a’, $next_low); ?> low // change “m/d g:i a” to use a different date format
<br><font color=”blue”>
<?php echo date(’m/d g:i a’ , $next_high); ?> high
<br></font>
<?php echo date( ‘m/d g:i a’ , $next_low + (12 * 3600) + (25 * 60)); ?> low<br />
<font color=”blue”>
<?php echo date( ‘m/d g:i a’ , $next_high + (12 * 3600) + (25 * 60)); ?> high</font>
<br><br><a href=”http://www.dawhoo.com/script.html”>dawhoo tide</a>

Tags: ,

About the Author

dawhoo has written 22 stories on this site.

2 Comments on “PHP Tide Clock”

  • Vince wrote on 12 July, 2009, 18:22

    Isn’t a htm file is needed to make this work?
    When I click .php files from my website they will downloads to my home PC.
    It would be helpful to show a complete example to viewers.

  • admin wrote on 26 July, 2009, 10:55

    That is a complete example. Most of the time, a php_includes is used to call the function. Your hosting company may not have PHP enabled, which would be very rare. However, more often the case deleting the cache clears up the problem with PHP wanting to download rather than render.

Write a Comment

Gravatars are small images that can show your personality. You can get your gravatar for free today!

Copyright © 2010 dawhoo. All rights reserved.
Powered by WordPress.org, Custom Theme and ComFi.com Calling Card Company.