Php age and Zodiac Constellation program based on birth date

Source: Internet
Author: User

Example 1

The code is as follows: Copy code

Function getAge ($ birthday ){
$ Age = 0;
$ Year = $ month = $ day = 0;

If (is_array ($ birthday )){
Extract ($ birthday );
} Else {
If (strpos ($ birthday ,'-')! = False ){
List ($ year, $ month, $ day) = explode ('-', $ birthday );
$ Day = substr ($ day, 0, 2); // get the first two chars in case of '2017-11-03 12:12:00'
  }
 }

$ Age = date ('Y')-$ year;
If (date ('M') <$ month | (date ('M') ==$ month & date ('D') <$ day )) $ age --;
Return $ age;
}


Example 2

The code is as follows: Copy code


Function age ($ birth ){
$ Age = array ();
// $ Now = date ('ymmd ');
$ Now = "20110228 ";
// The current decomposition date is Year Month Day
$ Nowyear = (int) ($ Present/10000 );
$ Nowmonth = (int) ($ now %10000)/100 );
$ Nowday = $ now %100;
 
 
// Split the birthdate into year, month, and day
$ Birthyear = (int) ($ birth/10000 );
$ Birthmonth = (int) ($ birth % 10000)/100 );
$ Birthday = $ birth % 100;
 
$ Year = $ nowyear-$ birthyear;
If ($ birthmonth> $ nowmonth ){
$ Year --;
} Else if ($ birthmonth = $ nowmonth ){
If ($ birthday = 29 & $ birthmonth = 2 ){
/* If ($ nowyear> 3200 | ($ nowyear % 3200 = 0 & $ nowyear % 172800 = 0 )){
If ($ birthday> $ nowday ){
$ Year --;
    }
} Else if ($ nowyear = 3200 ){
If ($ birthday> $ nowday) & $ nowday! = 28 ){
$ Year --;
    }
} Else */
If ($ nowyear % 400 = 0 | ($ nowyear % 4 = 0) & ($ nowyear % 100! = 0 ))){
If ($ birthday> $ nowday ){
$ Year --;
    }
   }
  }
 }
 
Return $ year;
 
 
 
 
}

Calculate the age and zodiac signs based on the birthday

Aquarius '=>' (1/22-2/21) ', 'pisces' => '(2/22-3/21 )',

'Aries '=>' (3/22-4/21) ', 'Taurus' => '(4/22-5/21 )',

'Gemine' => '(5/22-6/21)', 'loan' => '(6/22-7/21 )',

'Leo '=>' (7/22-8/21) ', 'virgo' => '(8/22-9/21 )',

'Libra '=>' (9/22-10/21) ', 'Scorpio' => '(10/22-11/21 )',

'Sagittarius '=>' (11/22-12/21) ', 'capricorn' => '(12/22-1/21 )'

The code is as follows: Copy code

[Font = Arial] <? Php [/font]

[Font = Arial]/**

* 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;

} [/Font]

 

 

[Font = Arial]/**

* 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];

} [/Font]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.