Php program code for determining constellation and Zodiac Based on birthday

Source: Internet
Author: User

Constellation judgment is very simple. We need to calculate all the time periods of each week, and then obtain the date for query. Below I will give you two examples. If you need them, you can refer to them.

Constellation: I wrote it according to this schedule, and the schedule may not be accurate.

'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 )'


Constellation function judgment based on date

The Code is as follows: Copy code

Function yige_constellation ($ month, $ day ){
// Check the parameter Validity
If ($ month <1 | $ month> 12 | $ day <1 | $ day> 31) return false;
 
// Constellation name and start date
$ Constellations = array (
Array ("20" => "babyworks "),
Array ("19" => "Pisces "),
Array ("21" => "Aries "),
Array ("20" => "Taurus "),
Array ("21" => "Gemini "),
Array ("22" => "cancer "),
Array ("23" => "Leo "),
Array ("23" => "Virgo "),
Array ("23" => "Libra "),
Array ("24" => "scorpio "),
Array ("22" => "Sagittarius "),
Array ("22" => "Capricorn ")
);
 
List ($ constellation_start, $ constellation_name) = each ($ constellations [(int) $ month-1]);
 
If ($ day <$ constellation_start) list ($ constellation_start, $ constellation_name) = each ($ constellations [($ month-2 <0 )? $ Month = 11: $ month-= 2]);
 
Return $ constellation_name;
}

The following is a more comprehensive examination of age, Zodiac, And Constellation Based on the birthday

The Code is as follows: Copy code

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

}


?>

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.