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>