/** *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′); |