导航:首页 > 编程语言 > php数字算星座

php数字算星座

发布时间:2023-03-06 05:53:39

A. 如何根据生日计算星座thinkphp

根据阳历生日

B. php获取SQLserver数据库中的datetime类型数据,然后根据日期得到星座。求可执行代码。

这个先设定时间,然后设定星座,这些都需要你事先知道的

C. 如何用php根据出生日期计算年龄和星座

<?php
function calcAge($birthday) {
$age = 0;
$signs = 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' => '摩羯座'));
if (!empty($birthday)) {
$age = strtotime($birthday);
if ($age === false) {
return 0;
}
list($y1, $m1, $d1) = explode("-", date("Y-m-d", $age));
list($y2, $m2, $d2) = explode("-", date("Y-m-d"), time());
$age = $y2 - $y1;
//下面是判断月份大小,如果只是逄年份的可以去掉,如果算上月份的话,比如:2000年4月1日,那算出来是16算,要到了4月,算出来才是17岁
if ((int)($m2 . $d2) < (int)($m1 . $d1)) {
$age -= 1;
}
//星座
$key = (int)$m1 - 1;
list($startSign, $signName) = each($signs[$key]);
if ($d1 < $startSign) {
$key = $m1 - 2 < 0 ? $m1 = 11 : $m1 -= 2;
list($startSign, $signName) = each($signs[$key]);
}
//return $signName;
}
return $age.$signName;
}
echo calcAge("2011-4-31");
?>

D. php 自动计算12生肖

<?php
//2002/10/23-->出生年月
/*
计算12个星座
计算12个生肖
计算年龄
*/
class timeage
{
public $y = 0;
public $m = 0;
public $d = 0;
public $age = 0;
public $time = 0;

public function __construct($time)
{
$this->time = $time;
$this->y = date('Y',$this->time);
$this->m = date('m',$this->time);
$this->d = date('d',$this->time);
}
public function getage()
{
$this->age = time() - $this->time;
$this->age = $this->age/60/60/24/365;
return (int)$this->age;
}
public function getconstellation()
{
switch ($this->m)
{
case 1:
if ($this->d < 19)
{
$this->constellation = '摩羯座';
return $this->constellation;
}
else
{
$this->constellation = '水瓶座';
return $this->constellation;
}
break;
case 2:
if ($this->d < 18)
{
$this->constellation = '水瓶座';
return $this->constellation;
}
else
{
$this->constellation = '双鱼座';
return $this->constellation;
}
break;
case 3:
if ($this->d < 20)
{
$this->constellation = '双鱼座';
return $this->constellation;
}
else
{
$this->constellation = '白羊座';
return $this->constellation;
}
break;
case 4:
if ($this->d < 19)
{
$this->constellation = '白羊座';
return $this->constellation;
}
else
{
$this->constellation = '金牛座';
return $this->constellation;
}
break;
case 5:
if ($this->d < 20)
{
$this->constellation = '金牛座';
return $this->constellation;
}
else
{
$this->constellation = '双子座';
return $this->constellation;
}
break;
case 6:
if ($this->d < 21)
{
$this->constellation = '双子座';
return $this->constellation;
}
else
{
$this->constellation = '巨蟹座';
return $this->constellation;
}
break;
case 7:
if ($this->d < 22)
{
$this->constellation = '巨蟹座';
return $this->constellation;
}
else
{
$this->constellation = '狮子座';
return $this->constellation;
}
break;
case 8:
if ($this->d < 22)
{
$this->constellation = '狮子座';
return $this->constellation;
}
else
{
$this->constellation = '处女座';
return $this->constellation;
}
break;
case 9:
if ($this->d < 22)
{
$this->constellation = '处女座';
return $this->constellation;
}
else
{
$this->constellation = '天秤座';
return $this->constellation;
}
break;
case 10:
if ($this->d < 23)
{
$this->constellation = '天秤座';
return $this->constellation;
}
else
{
$this->constellation = '天蝎座';
return $this->constellation;
}
break;
case 11:
if ($this->d < 22)
{
$this->constellation = '天蝎座';
return $this->constellation;
}
else
{
$this->constellation = '射手座';
return $this->constellation;
}
break;
case 12:
if ($this->d < 20)
{
$this->constellation = '射手座';
return $this->constellation;
}
else
{
$this->constellation = '摩羯座';
return $this->constellation;
}
break;
}
}
public function getzodiac()
{
$this->animals = array('鼠', '牛', '虎', '兔', '龙', '蛇','马', '羊', '猴', '鸡', '狗', '猪');
$this->zodiac = ($this->y - 1900) % 12;
return $this->animals[$this->zodiac];
}
}

$age = strtotime('1993-07-25');
echo $age;
$a = new timeage($age);
echo '<br>';
echo $a->y;
echo '<br>';
echo $a->m;
echo '<br>';
echo $a->d;
echo '<br>';
echo $a->time;
echo '<br>';
echo $a->age;
echo '<br>';
echo $a->getage();
echo '<br>';
echo $a->getconstellation();
echo '<br>';
echo $a->getzodiac();

//没事干替你写了个全部的功能函数 写代码类 记得给好评

E. php怎么把日期转成星座

你要有一份星座对应时间段的数据库

阅读全文

与php数字算星座相关的资料

热点内容
cad安装卡在解压 浏览:615
编程精灵g540 浏览:256
手机文档解压之后解压包去哪儿了 浏览:923
java中网络编程重要吗 浏览:683
如何登录别人的服务器 浏览:626
调度系统软件python 浏览:205
微信大转盘抽奖源码 浏览:497
压缩机损坏的表现 浏览:862
同步数据服务器怎么用 浏览:634
163邮箱服务器的ip地址 浏览:50
服务器跟域是什么 浏览:128
rails启动命令 浏览:465
logistic命令怎么用 浏览:738
c语言点滴pdf 浏览:747
linuxrtc编程 浏览:258
linux打包并压缩命令 浏览:644
aes加密的证书格式 浏览:99
oracledbcalinux 浏览:844
酬勤任务app怎么被特邀 浏览:199
android应用文件夹 浏览:1002