note 81031 added to language.oop5.basic

From: Date: Mon, 11 Feb 2008 20:14:44 +0000
Subject: note 81031 added to language.oop5.basic
Groups: php.notes 
Request: Send a blank email to php-notes+get-136051@lists.php.net to get a copy of this message
<?php /************************************************************** # TITLE : Object Oriented Approach to countdown to any particular date or event * # Same procedural snipped is posted in Help Manual ---> date() # http://www.php.net/manual/en/function.date.php # If you compare both snippets, It would be easy to understand PHP-OOPs! ***************************************************************/ //Any of following input can be retrieved by GET OR POST. //Input is set for New Year event. $year = '2009'; $month= '01'; $day = '01'; $hour = '00'; $minute = '00'; $second = '00'; $date = array($hour,$minute,$second,$month,$day,$year); //Defining class bt keyword class class DateCountDown { //Class member definition - Easy to remember class members var $year = ""; var $month= ""; var $day = ""; var $hour = ""; var $minute = ""; var $second = ""; var $date = ""; var $dl = ""; var $hl = ""; var $ml = ""; var $sl = ""; var $return = ""; //Countdown to particular Function function countdown(){ global $return; global $countdown_date; global $date; list ($hour, $minute, $second, $month, $day, $year)= $date; $countdown_date = mktime($hour, $minute, $second, $month, $day, $year); $today = time(); $diff = $countdown_date - $today; if ($diff < 0)$diff = 0; $dl = floor($diff/60/60/24); $hl = floor(($diff - $dl*60*60*24)/60/60); $ml = floor(($diff - $dl*60*60*24 - $hl*60*60)/60); $sl = floor(($diff - $dl*60*60*24 - $hl*60*60 - $ml*60)); // OUTPUT $return = array($dl, $hl, $ml, $sl); return ($return); } } //Making New Object for the class CountDownDate $date_obj = new DateCountDown($date); //Function (Method) call by an object to function countdown $date_obj -> countdown(); //Making varialbes $dl => Days Left, $hl => Hours Left and so on from $return array list($dl,$hl,$ml,$sl) = $return; //Browser Output echo "Today's date ".date("F j, Y, g:i:s A")."<br/>"; echo "Countdown date ".date("F j, Y, g:i:s A",$countdown_date)."<br/>"; echo "\n<br>"; echo "Countdown ".$dl." days ".$hl." hours ".$ml." minutes ".$sl." seconds left"."\n<br>"; /* Above snippet produces following output: Today's date February 11, 2008, XX:XX:XX PM Countdown date January 1, 2009, 12:00:00 AM Countdown 324 days XX hours XX minutes XX seconds left */ ?> ---- Server IP: 69.147.83.197 Probable Submitter: 208.72.122.78 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.basic.php Edit -- https://master.php.net/note/edit/81031 Del: integrated -- https://master.php.net/note/delete/81031/integrated Del: useless -- https://master.php.net/note/delete/81031/useless Del: bad code -- https://master.php.net/note/delete/81031/bad+code Del: spam -- https://master.php.net/note/delete/81031/spam Del: non-english -- https://master.php.net/note/delete/81031/non-english Del: in docs -- https://master.php.net/note/delete/81031/in+docs Del: other reasons-- https://master.php.net/note/delete/81031 Reject -- https://master.php.net/note/reject/81031 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#136051) next »