HTML file coding (filename form.html or whatever you choose):
PHP exercise 3: Birthday calculator
See source code here
PHP File coding (filename exercise2process.php):
12) {
echo "Your month number bigger than 12!
";
}
//turn what you have entered into a date object:
$date=$year."-".$month."-".$day;
$birthdate=date_create($date);
//get today's date
$today=date_create();
// use it
echo "You were born on the ".$day."th day of the ".$month."th month, in the year ".$year.".
";
echo date_format($birthdate,"Y/m/d")."
";
$interval = date_diff($today, $birthdate);
echo "You have lived for ".$interval->format('%a')." days.
";
//star sign checker
$starsign = array
(
array("Aries",3,21,4,20),
array("Taurus",4,21,5,21),
array("Gemini",5,22,6,21),
array("Cancer",6,22,7,23),
array("Leo",7,24,8,23),
array("Virgo",8,24,9,23),
array("Libra",9,24,10,23),
array("Scorpio",10,24,11,22),
array("Sagittarius",11,23,12,22),
array("Capricorn",12,23,1,20),
array("Aquarius",1,21,2,19),
array("Pisces",2,20,3,20),
);
for ($x=0;$x<=11;$x++) {
if ($month==$starsign[$x][1] && $day>=$starsign[$x][2]) {
echo "Your star sign is ".$starsign[$x][0];
}
if ($month==$starsign[$x][3] && $day<=$starsign[$x][4]) {
echo "Your star sign is ".$starsign[$x][0];
}
}
// echo $interval->format('%R%a days');
?>