星座判断很简单我们要统计出每个星期所有日期时间段了,然后获取日期进行查询即可了,下面我给大家举两个实例,有需要的同学可参考.
星座:我是根据这个时间表写的,该时间表未必准确.
'水瓶座'=>'(1/22-2/21)', '双鱼座'=>'(2/22-3/21)',
'白羊座'=>'(3/22-4/21)', '金牛座'=>'(4/22-5/21)',
'双子座'=>'(5/22-6/21)', '巨蟹座'=>'(6/22-7/21)',
'狮子座'=>'(7/22-8/21)', '处女座'=>'(8/22-9/21)',
'天秤座'=>'(9/22-10/21)', '天蝎座'=>'(10/22-11/21)',
'射手座'=>'(11/22-12/21)', '摩羯座'=>'(12/22-1/21)'
根据日期判断星座函数
实例代码如下:
- function yige_constellation($month, $day) {
-
- if ($month < 1 || $month > 12 || $day < 1 || $day > 31) return false;
-
-
- $constellations = array(
- array( "20" => "宝瓶座"),
- array( "19" => "双鱼座"),
- array( "21" => "白羊座"),
- array( "20" => "金牛座"),
- array( "21" => "双子座"),
- array( "22" => "巨蟹座"),
- array( "23" => "狮子座"),
- array( "23" => "处女座"),
- array( "23" => "天秤座"),
- array( "24" => "天蝎座"),
- array( "22" => "射手座"),
- array( "22" => "摩羯座")
- );
-
- 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;
- }
下面这个更全面可直接根据生日检查年龄,生肖,星座
实例代码如下:
- <?php
-
-
-
-
-
-
-
- function get_constellation($birth_month,$birth_date)
- {
-
- $birth_month = strval($birth_month);
-
- $constellation_name = array(
- '水瓶座','双鱼座','白羊座','金牛座','双子座','巨蟹座',
- '狮子座','处女座','天秤座','天蝎座)','射手座','摩羯座'
- );
-
- 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;
- }
-
-
-
-
-
-
-
- function get_animal($birth_year)
- {
-
- $animal = array(
- '子鼠','丑牛','寅虎','卯兔','辰龙','巳蛇',
- '午马','未羊','申猴','酉鸡','戌狗','亥猪'
- );
-
- $my_animal = ($birth_year-1900)%12;
- return $animal[$my_animal];
- }
-
-
-
-
-
-
-
-
-
-
-
-
- function get_age($birth_year,$birth_month,$birth_date)
- {
- $now_age = 1;
- $full_age = 0;
-
- $now_year = date('Y',time());
- $now_date_num = date('z',time());
- $birth_date_num = date('z',mktime(0,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;
- }
-
- ?>
|