Home > Backend Development > PHP Tutorial > php获取指定日期干支纪年,生肖和星座信息的方法

php获取指定日期干支纪年,生肖和星座信息的方法

WBOY
Release: 2016-06-20 13:04:00
Original
1289 people have browsed it

分享一个利用php根据日期或时间戳获取相应的干支纪年,生肖和星座信息的函数方法。

具体函数代码以及使用方法如下:

<p>/**</p>判断干支、生肖和星座<br />*/<br />function birthext($birth){<br /> if(strstr($birth,'-')===false&&strlen($birth)!==8){<br /> $birth=date("Y-m-d",$birth);<br /> }<br /> if(strlen($birth)===8){<br /> if(eregi('([0-9]{4})([0-9]{2})([0-9]{2})$',$birth,$bir))<br /> $birth="{$bir[1]}-{$bir[2]}-{$bir[3]}";<br /> }<br /> if(strlen($birth)<8){<br /> return false;<br /> }<br /> $tmpstr= explode('-',$birth);<br /> if(count($tmpstr)!==3){<br /> return false;<br /> }<br /> $y=(int)$tmpstr[0];<br /> $m=(int)$tmpstr[1];<br /> $d=(int)$tmpstr[2];<br /> $result=array(); <br /> $xzdict=array('摩羯','水瓶','双鱼','白羊','金牛','双子','巨蟹','狮子','处女','天秤','天蝎','射手');<br /> $zone=array(1222,122,222,321,421,522,622,722,822,922,1022,1122,1222); <br /> if((100*$m+$d)>=$zone[0]||(100*$m+$d)<$zone[1]){<br /> $i=0;<br /> }else{<br /> for($i=1;$i<12;$i++){<br /> if((100*$m+$d)>=$zone[$i]&&(100*$m+$d)<$zone[$i+1]){ break; } <br /> } <br /> }<br /> $result['xz']=$xzdict[$i].'座';<br /> $gzdict=array(array('甲','乙','丙','丁','戊','己','庚','辛','壬','癸'),array('子','丑','寅','卯','辰','巳','午','未','申','酉','戌','亥'));<br /> $i= $y-1900+36;//http://www.scutephp.com/<br /> $result['gz']=$gzdict[0][($i%10)].$gzdict[1][($i%12)];<br /> $sxdict=array('鼠','牛','虎','兔','龙','蛇','马','羊','猴','鸡','狗','猪'); <br /> $result['sx']=$sxdict[(($y-4)%12)];<br /> return $result;<br /><p>}
Copy after login

使用实例如下:

<p><?php</p>header("Content-Type:text/html;charset=utf-8");<br />echo '<pre class="brush:php;toolbar:false">';//http://www.scutephp.com/<br />$arr=birthext('1373287361'); //时间戳<br />print_r($arr);<br />$arr=birthext('2013-07-08');<br />print_r($arr);<br />$arr=birthext('20130708');<br /><p>print_r($arr);</p>
Copy after login

打印结果如下:

Array

(
    [xz] => 巨蟹座
    [gz] => 癸巳
    [sx] => 蛇
)
Array
(
    [xz] => 巨蟹座
    [gz] => 癸巳
    [sx] => 蛇
)
Array
(
    [xz] => 巨蟹座
    [gz] => 癸巳
    [sx] => 蛇
)


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template