CarlosPSY’s Weblog is no longer available.



OOP PHP Class that brings you your birth’s date.

In my free time I’ve maked a class in PHP that shows you your DAY of birth, it’s very usefull if you want to introduce in the world of the PHP Objects Oriented Programming (OOP) :)

<?php
///////////////////////////////////////////////////////////
## PHP Class that brings you your birth’s day :) //
## By: Carlos GarcĂ­a (http://carlospsy92.wordpress.com) //
## Date: April, Thursday 10, 2008 //
## License: GNU (http://www.gnu.org/) //
//////////////////////////////////////////////////////
class myDate {
var $myDayUD; //Day with timestamp format
var $myDay;
var $myMonth;
var $dayN; //Day in number
var $yearN; //Year in number
var $days = array ( //I putted it into an array that you can change the lang of the script.
1 => ‘Monday’,
2 => ‘Tuesday’,
3 => ‘Wednesday’,
4 => ‘Thursday’,
5 => ‘Friday’,
6 => ‘Saturday’,
7 => ‘Sunday’
);
var $months = array (
1 => ‘January’,
2 => ‘February’,
3 => ‘March’,
4 => ‘April’,
5 => ‘May’,
6 => ‘June’,
7 => ‘July’,
8 => ‘August’,
9 => ‘September’,
10 => ‘October’,
11 => ‘November’,
12 => ‘December’
);
function myDate ($day, $month, $year) {
$this->myDayUD = mktime(0, 0, 0, $month, $day, $year); //Pass the date to Unix timestamp.
$this->dayN = $day;
$this->yearN = $year;
}
function ShowDay () {
$this->myDay = $this->days[date('N', $this->myDayUD)]; //Pass the date to the day.
return $this->myDay; //Returns the day.
}
function ShowMonth () {
$this->myMonth = $this->months[date('n', $this->myDayUD)]; //Pass the date to the month.
return $this->myMonth; //Returns the month.
}
function ShowDayN () {
return $this->dayN;
}
function ShowYearN () {
return $this->yearN;
}
}
$myDay = new myDate (29, 05, 1992); //Call to the builder, sending the parameters (dd,mm,yyyy).
echo ‘You born in <b>’.$myDay->ShowDay().’</b>, ‘.$myDay->ShowdayN().’ of ‘.$myDay->ShowMonth().’ in the year: ‘.$myDay->ShowYearN().’.'; //Shows the day in screen
?>

Greets, and I hope that it serves to you :) .

PS.: You can modify the languaje of the shown message ;) .


Leave a Comment

(required)

(required)



Formatting your comment
Back to Top | Textarea: Larger | Smaller