<? 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; } ?>
|