導航:首頁 > 編程語言 > 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