网站制作学习网PHP→正文:php判断天干地支星座
字体:

php判断天干地支星座

PHP 2009/10/30 14:23:55  点击:不统计

php通过函数,输入出生年月日来判断人的天干地支,生肖星座等
/**
* 判断干支、生肖和星座
** @param string $type 返回类型: XZ星座|GZ干支|SX生肖
* @param date   $birth 年月日(yyyy-mm-dd)
** @author bottle hhyisw@163.com
**@forasp.cn整理,网站制作学习网
*/
function birthext($type, $birth){   
$tmpstr= explode('-', $birth);
$y = (int)$tmpstr[0];
$m = (int)$tmpstr[1];
$d = (int)$tmpstr[2];
$result = '';  
switch ($type) {   
case 'XZ':  //星座
$XZDict = array('摩羯', '宝瓶', '双鱼', '白羊', '金牛', '双子', '巨蟹', '狮子', '处女', '天秤', '天蝎', '射手');  
$Zone   = array(1222,122,222,321,421,522,622,722,822,922,1022,1122,1222);   //www.forasp.cn整理
if((100 * $m + $d) >= $Zone[0] || (100 * $m + $d) < $Zone[1]){  
$i=0;  
}else{  
for($i=1;$i<12;$i++){   
if((100 * $m + $d) >= $Zone[$i] && (100 * $m + $d)< $Zone[$i+1])  break;  
}  
}  
$result = $XZDict[$i] . '座';
break;  
case 'GZ': //干支
$GZDict = array(array('甲', '乙', '丙', '丁', '戊', '己', '庚', '辛', '壬', '癸'), array('子', '丑', '寅', '卯', '辰', '巳', '午', '未', '申', '酉', '戌', '亥'));
$i= $y-1900+36 ;  
$result = $GZDict[0][($i%10)] . $GZDict[1][($i%12)];
break;  
case 'SX': //生肖http://www.forforasp.cnasp.cn
$SXDict = array('鼠', '牛', '虎', '兔', '龙', '蛇', '马', '羊', '猴', '鸡', '狗', '猪');
$result = $SXDict[(($y-4)%12)];  
break;  
}  
return $result;  
}

本函数是转载的,原文在:http://qeephp.com/bbs/thread-5052-1-1.html//网站制作学习网整理转载

·上一篇:PHP清除html代码 >>    ·下一篇:GD库 >>
推荐文章
最新文章