Login   Register  
PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Tomas Kavalek  >  Sun - set, rise, dawn, dusk  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example how to use sun.class.php
Class: Sun - set, rise, dawn, dusk
Calculate location sunset and sunrise time
Author: By
Last change:
Date: 2008-04-03 22:09
Size: 1,615 bytes
 

Contents

Class file image Download
<?php
  
/* ************************************************************************ */
  
function sunset_sunrise($object$days 7) {
    
$days $days <= 30 $days 30;
    
$start date("d");
    
$start_day date("w");
    
$name_day = array("Neděle""Pondělí""Úterý""Středa""Čtvrtek""Pátek""Sobota");
    
$stop = ($start $days) < date("t") ? ($start $days) : date("t"); 
    
$it 0;
    
$return = array(array());
    for(
$i $start$i $stop$i++) {
      
$return[$it]["date"] = $i "." date("n.Y") . " - " $name_day[fmod($start_day++, 7)];
      
$return[$it]["sunrise"] = $object->rise(mktime(000date("n"), $idate("Y")));
      
$return[$it]["sunset"] = $object->set(mktime(000date("n"), $idate("Y")));
      
$it++;
    }
    
// Next month, if needed
    
if($it $days) {
      
$start 1;
      
$stop = ($days 1) - $it;
      
$month date("n") + 1;
      for(
$i $start$i $stop$i++) {
        
$return[$it]["date"] = $i "." $month "." date("Y") . " - " $name_day[fmod($start_day++, 7)];
        
$return[$it]["sunrise"] = $object->rise(mktime(000$month$idate("Y")));
        
$return[$it]["sunset"] = $object->set(mktime(000$month$idate("Y")));
        
$it++;
      }
    }
    return 
$return;
  }
  
/* ************************************************************************ */
  
require_once("./sun.php");
  
$sun = new SUN();
  
$sun->set_timezone(1);
  
$sun->set_coords("50°7'0.64\"N 16°13'1.35\"E");
  
$times sunset_sunrise($sun);
  
// Print result
  
print_r($times);    
?>