PHP calculates constellation and Zodiac program based on birthday

Source: Internet
Author: User

Capricorn (12/22–1/19), Aquarius (1/20–2/18), Pisces (2/19–3/20), Aries (3/21–4/20),
Taurus (4/21–5/20), Gemini (5/21–6/21), Cancer (6/22–7/22), Leo (7/23–8/22),
Virgo (8/23–9/22), Libra (9/23–10/22), Scorpio (10/23–11/21), Sagittarius (11/22–12/21)

The code is as follows Copy Code

/**
*getconstellation According to birth birthday get constellation
*
* @param String $brithday The date format used to get the constellation is YYYY-MM-DD
*
* @param Array $format to return the name of the constellation
*
* @return String
*/
function Getconstellation ($birthday, $format =null)
{
$pattern = '/^d{4}-d{1,2}-d{1,2}$/';
if (!preg_match ($pattern, $birthday, $matchs))
{
return null;
}
$date = Explode ('-', $birthday);
$year = $date [0];
$month = $date [1];
$day = $date [2];
if ($month <1 | | $month >12 | | $day < 1 | | $day >31)
{
return null;
}
Set Constellation Array
$constellations = Array (
' Capricorn ', ' Aquarius ', ' Pisces ', ' Aries ', ' Taurus ', ' Gemini ',
' Cancer ', ' Leo ', ' Virgo ', ' Libra ', ' Scorpio ', ' Sagittarius ',
or $constellations = Array (
' Capricorn ', ' Aquarius ', ' Pisces ', ' Aries ', ' Taurus ', ' Gemini ',
' Cancer ', ' Leo ', ' Virgo ', ' Libra ', ' Scorpio ', ' Sagittarius ',);
Sets the array for the end date of the constellation, used to determine
$enddays = Array (19, 18, 20, 20, 20, 21, 22, 22, 22, 22, 21, 21,);
If the parameter format is set, the return value takes an array provided by format, otherwise the default array is used
if ($format!= null)
{
$values = $format;
}
Else
{
$values = $constellations;
}
Judge constellations by month and date
Switch ($month)
{
Case 1:
if ($day <= $enddays [0])
{
$constellation = $values [0];
}
Else
{
$constellation = $values [1];
}
Break
Case 2:
if ($day <= $enddays [1])
{
$constellation = $values [1];
}
Else
{
$constellation = $values [2];
}
Break
Case 3:
if ($day <= $enddays [2])
{
$constellation = $values [2];
}
Else
{
$constellation = $values [3];
}
Break
Case 4:
if ($day <= $enddays [3])
{
$constellation = $values [3];
}
Else
{
$constellation = $values [4];
}
Break
Case 5:
if ($day <= $enddays [4])
{
$constellation = $values [4];
}
Else
{
$constellation = $values [5];
}
Break
Case 6:
if ($day <= $enddays [5])
{
$constellation = $values [5];
}
Else
{
$constellation = $values [6];
}
Break
Case 7:
if ($day <= $enddays [6])
{
$constellation = $values [6];
}
Else
{
$constellation = $values [7];
}
Break
Case 8:
if ($day <= $enddays [7])
{
$constellation = $values [7];
}
Else
{
$constellation = $values [8];
}
Break
Case 9:
if ($day <= $enddays [8])
{
$constellation = $values [8];
}
Else
{
$constellation = $values [9];
}
Break
Case 10:
if ($day <= $enddays [9])
{
$constellation = $values [9];
}
Else
{
$constellation = $values [10];
}
Break
Case 11:
if ($day <= $enddays [10])
{
$constellation = $values [10];
}
Else
{
$constellation = $values [11];
}
Break
Case 12:
if ($day <= $enddays [11])
{
$constellation = $values [11];
}
Else
{
$constellation = $values [0];
}
Break
}
return $constellation;
}
JS format:
Calculates the JS small function of the constellation according to the month and date of the birthday (most simple)
Calculates the constellation according to the month and date of the birthday. http://blog.111cn.net/cuixiping/
function Getastro (month,day) {
var s= "Capricorn Aquarius Pisces aries taurus Gemini giant crab lion Virgin libra scorpio Sagittarius Capricorn";
var arr=[20,19,21,21,21,22,23,23,23,23,22,22];
Return S.substr (month*2-(day<arr[month-1]?2:0), 2);
}
Takes the constellation, the parameter is the month and the date respectively
function Getxingzuo (month,day) {
by Go_rush (Asun) from http://ashun.cnblogs.com/
var d=new Date (1999,month-1,day,0,0,0);
var arr=[];
Arr.push (["Capricorn", New Date (1999, 0, 1,0,0,0)])
Arr.push (["Aquarius", New Date (1999, 0,20,0,0,0)])
Arr.push ([Pisces, New Date (1999, 1,19,0,0,0)])
Arr.push (["Aries", New Date (1999, 2,21,0,0,0)])
Arr.push (["Taurus", New Date (1999, 3,21,0,0,0)])
Arr.push (["Gemini", New Date (1999, 4,21,0,0,0)])
Arr.push (["Cancer", New Date (1999, 5,22,0,0,0)])
Arr.push (["Leo", New Date (1999, 6,23,0,0,0)])
Arr.push (["Virgo", New Date (1999, 7,23,0,0,0)])
Arr.push (["Libra", New Date (1999, 8,23,0,0,0)])
Arr.push (["Scorpio", New Date (1999, 9,23,0,0,0)])
Arr.push (["Sagittarius", New Date (1999,10,22,0,0,0))
Arr.push (["Capricorn", New Date (1999,11,22,0,0,0))
for (Var i=arr.length-1;i>=0;i–) {
if (D>=arr[i][1]) return arr[i][0];
}
}
function Getxingzuo (month,day) {
var s= "Capricorn Aquarius Pisces aries taurus Gemini giant crab lion Virgin libra scorpio Sagittarius Capricorn";
var arr=[19,50,84,116,148,181,214,246,278,310,341,373,383];
for (Var i=0;i<arr.length;i++) {
if ((((month-1) <<5) +day) <= Arr[i]) return s.substr (i*2,2);
}
return "error";
}
Calculating the Zodiac:
function Birthday2borntag ($birthday) {
$year = substr ($birthday, 0,4);
$bornTagarray = Array ("Monkey", "Chicken", "dog", "pig", "rat", "ox", "Tiger", "Rabbit", "dragon", "Snake",

"Horse", "sheep");
$index = $year% 12;
$bornTag = $bornTagarray [$index];
return $bornTag;
}
echo Birthday2borntag (' 1983-12-19′);

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.