生肖查询php

三堂网 > | 发布时间:2019-11-18T09:55:07 更新时间:2024-08-30T05:01:41
【PHP输入年份查询属相的代码。】

PHP通过年份查询属相示例代码如下,具体逻辑体现在代码中。

?php 

//判断是否为日期格式,默认时间格式为Y-m-d

function is_date($dateStr,$fmt="Y-m-d"){

    $dateArr = explode("-",$dateStr);

    if(empty($dateArr)){

  return false;

    }

    foreach($dateArr as $val){

  if(strlen($val)2){

$val="0".$val;

  }

  $newArr[]=$val;

    }

    $dateStr =implode("-",$newArr);

    $unixTime=strtotime($dateStr);

    $checkDate= date($fmt,$unixTime);

    if($checkDate==$dateStr)

  return true;

    else

  return false;

}

//通过出生年月获取属相

function getShuXiang($bithdayDate){

    

    //判断输入日期格式

    if(!is_date($bithdayDate)){

  

  echo "日期输入错误,请检查!";

    }

    //1900年是鼠年

    $data = array('鼠','牛','虎','兔','龙','蛇','马','羊','猴','鸡','狗','猪');

    $index = ($bithdayDate-1900)%12;

    return $data[$index];

}

echo "属相:".getShuXiang("1989-05-19");

//属相:蛇

?

【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();

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

生肖查询php相关文章:

本日冲什么属相 2020年10月9日生肖相冲查询
本日冲什么属相 2020年10月9日生肖相冲查询

虽然每个人的运气无法去探究到,每一天的运势也在变来变去,但是如果让人的运气对上日子的运势,那边会有奇佳的效果。而生肖正是其中重要一环。每一天的生肖相冲不一样,我们可以根...

今天冲什么生肖 2020年6月22日生肖相冲查询
今天冲什么生肖 2020年6月22日生肖相冲查询

今天冲什么生肖公历:2020年6月22日星期一巨蟹座农历:庚子年壬午月丙申日五月初二今天属什么:猴今天冲什么:猴日冲(庚寅)虎生肖相冲分析:冲虎日将冲到所有的虎,申寅相冲,即猴和虎相...

今日生肖相冲查询 2019年12月18日
今日生肖相冲查询 2019年12月18日

公历2019-12-18农历十一月二十三日星期三今天属什么:牛今天冲什么:牛日冲(癸未)羊今日时辰相冲对照表子时23:00-00:59,甲子时,冲(戊午)马,煞南,天寡黑道,凶丑时01:00-02:59,乙丑时,冲(己...

今日生肖相冲查询 2019年12月18日
今日生肖相冲查询 2019年12月18日

公历2019-12-18农历十一月二十三日星期三今天属什么:牛今天冲什么:牛日冲(癸未)羊今日时辰相冲对照表子时23:00-00:59,甲子时,冲(戊午)马,煞南,天寡黑道,凶丑时01:00-02:59,乙丑时,冲(己...