|
/**
* GetConstellation: generates a Constellation Based on the birth date.
*
* @ Param String $ brithday: The Date Format of the constellation is yyyy-mm-dd.
*
* @ Param Array $ format is used to return the constellation name.
*
* @ 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 the constellation Array
$ Constellations = array (
'Capricorn ', 'aquarius', 'pisces ', 'aries', 'taurus ', 'gemine ',
'Cancer ', 'Leo', 'virgo ', 'libra', 'scorpio ', 'sagittarius ',);
// Or$ Constellations = array (
'Capricorn', 'aquarius', 'pisces ', 'aries', 'taurus', 'gemini ',
'Cancer', 'Leo ', 'virgo', 'libra', 'scorpio', 'sagittarius ',);
// Sets the array of the constellation end date for judgment.
$ Enddays = array (19, 18, 20, 20, 20, 21, 22, 22, 22, 22, 21, 21 ,);
// If the format parameter is set, the returned value uses the array provided by format. Otherwise, the default array is used.
If ($ format! = Null)
{
$ Values = $ format;
}
Else
{
$ Values = $ constellations;
}
// Determine the Constellation Based on the 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:
Calculate the js function of the Constellation Based on the month and date of the birthday (simplest)
// Calculate the Constellation Based on the month and date of the birthday. Http://blog.111cn.net/cuixiping/
Function getAstro (month, day ){
Var s = "Capricorn water bottle, Pisces, goat, Taurus, Gemini, cancer, lions, virgins, Libra, Scorpio, Sagittarius ";
Var arr = [20, 19, 21, 23,];
Return s. substr (month * 2-(day}
// Obtain the Constellation. The parameters are month and date.
Function getxingzuo (month, day ){
// By Go_Rush (A Shun) from http://ashun.cnblogs.com/
Var d = new Date (1999, month-1, day, 0 );
Var arr = [];
Arr. push (["Capricorn", new Date (1999, 0,)])
Arr. push (["Aquarius", new Date (1999, 0, 0)])
Arr. push (["Pisces", new Date (1999, 0, 0)])
Arr. push (["Aries", new Date (1999, 0, 0)])
Arr. push (["Taurus", new Date (1999, 21, 0)])
Arr. push (["Gemini", new Date (1999, 21, 0)])
Arr. push (["cancer", new Date (1999, 22, 0)])
Arr. push (["Leo", new Date (1999, 0, 0)])
Arr. push (["Virgo", new Date (1999, 0, 0)])
Arr. push (["Libra", new Date (1999, 0, 0)])
Arr. push (["scorpio", new Date (1999, 9, 23, 0)])
Arr. push (["Sagittarius", new Date (,)])
Arr. push (["Capricorn", new Date (,)])
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 water bottle, Pisces, goat, Taurus, Gemini, cancer, lions, virgins, Libra, Scorpio, Sagittarius ";
Var arr = [19,50, 84,116,148,181,214,246,278,310,341,373,383];
For (var I = 0; iif (month-1) <5) + day) <= arr [I]) return s. substr (I * 2 );
}
Return "error ";
}
Calculate the zodiac:
Function birthday2BornTag ($ birthday ){
$ Year = substr ($ birthday, 0, 4 );
$ BornTagarray = array ("monkey", "chicken", "dog", "Swine", "rat", "Ox", "Tiger", "rabbit ", "Dragon", "snake ",
"Horse", "goat ");
$ Index = $ year % 12;
$ BornTag = $ bornTagarray [$ index];
Return $ bornTag;
}
Echo birthday2BornTag ('2017-12-19 ′); |