|
<? Php
/**
* Calculate the Constellation Based on the month and date of the birthday.
*
* @ Param int $ birth_month
* @ Param int $ birth_date
* @ Return string
*/
Function get_constellation ($ birth_month, $ birth_date)
{
// When judging, in order to avoid doubts such as "1" and "true", or whether the judgment statement is always true, it is processed as a string.
$ Birth_month = strval ($ birth_month );
$ Constellation_name = array (
'Aquarius ', 'pisces', 'aries ', 'taurus', 'gemine', 'cancer ',
'Leo ', 'virgo', 'libra ', 'scorpio)', 'sagittarius ', 'capricorn'
);
If ($ birth_date <= 22)
{
If ('1 '! = $ Birth_month)
{
$ Constellation = $ constellation_name [$ birth_month-2];
}
Else
{
$ Constellation = $ constellation_name [11];
}
}
Else
{
$ Constellation = $ constellation_name [$ birth_month-1];
}
Return $ constellation;
}
/**
* Calculate the Chinese zodiac Based on the Year in the birthday.
*
* @ Param int $ birth_year
* @ Return string
*/
Function get_animal ($ birth_year)
{
// The Year 1900 is the year of the mouse
$ Animal = array (
'Zombies ', 'Ugly niu', 'tigers', 'rabbits, 'chen long', 'snakes ',
'Afternoon m', 'goat ', 'Monkey Shen', 'youzichen ', 'pig', 'pig pig'
);
$ My_animal = ($ birth_year-1900) % 12;
Return $ animal [$ my_animal];
}
/**
* Calculate the age based on the birthday.
*
* The Unix timestamp calculation is the most accurate, but it is not easy to handle the situation that was born before January 1, 1970.
* We also need to consider the leap year issue, so we will temporarily abandon this method of development and keep our thoughts
*
* @ Param int $ birth_year
* @ Param int $ birth_month
* @ Param int $ birth_date
* @ Return int
*/
Function get_age ($ birth_year, $ birth_month, $ birth_date)
{
$ Now_age = 1; // actual age, based on the age of 1 at birth
$ Full_age = 0; // indicates the age. The variable is stored and can be modified at any time.
$ Now_year = date ('y', time ());
$ Now_date_num = date ('Z', time (); // The day of the year
$ Birth_date_num = date ('Z', mktime (0, 0, $ birth_month, $ birth_date, $ birth_year ));
$ Difference = $ now_date_num-$ birth_date_num;
If ($ difference> 0)
{
$ Full_age = $ now_year-$ birth_year;
}
Else
{
$ Full_age = $ now_year-$ birth_year-1;
}
$ Now_age = $ full_age + 1;
Return $ now_age;
}
?>
|