php根据日期或时间戳获取星座信息和生肖等信息,php星座
分享一个利用php根据日期或时间戳获取相应的干支纪年,生肖和星座信息的函数方法,具体函数代码以及使用方法如下:
/** 判断干支、生肖和星座 */ function birthext($birth){ if(strstr($birth,'-')===false&&strlen($birth)!==8){ $birth=date("Y-m-d",$birth); } if(strlen($birth)===8){ if(eregi('([0-9]{4})([0-9]{2})([0-9]{2})$',$birth,$bir)) $birth="{$bir[1]}-{$bir[2]}-{$bir[3]}"; } if(strlen($birth)<8){ return false; } $tmpstr= explode('-',$birth); if(count($tmpstr)!==3){ return false; } $y=(int)$tmpstr[0]; $m=(int)$tmpstr[1]; $d=(int)$tmpstr[2]; $result=array(); $xzdict=array('摩羯','水瓶','双鱼','白羊','金牛','双子','巨蟹','狮子','处女','天秤','天蝎','射手'); $zone=array(1222,122,222,321,421,522,622,722,822,922,1022,1122,1222); 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['xz']=$xzdict[$i].'座'; $gzdict=array(array('甲','乙','丙','丁','戊','己','庚','辛','壬','癸'),array('子','丑','寅','卯','辰','巳','午','未','申','酉','戌','亥')); $i= $y-1900+36; $result['gz']=$gzdict[0][($i%10)].$gzdict[1][($i%12)]; $sxdict=array('鼠','牛','虎','兔','龙','蛇','马','羊','猴','鸡','狗','猪'); $result['sx']=$sxdict[(($y-4)%12)]; return $result; }
使用实例如下:
<?php header("Content-Type:text/html;charset=utf-8"); echo '<pre class="brush:php;toolbar:false">'; $arr=birthext('1373287361'); //时间戳 print_r($arr); $arr=birthext('2013-07-08'); print_r($arr); $arr=birthext('20130708'); print_r($arr);
打印结果如下:
以上就是关于php根据日期或时间戳获取星座信息和生肖等信息的函数方法,希望对大家的学习有所帮助。
Statement
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

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Assassin's Creed Shadows: Seashell Riddle Solution
2 weeks agoByDDD
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 English version
Recommended: Win version, supports code prompts!

Dreamweaver CS6
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft