導航:首頁 > 編程語言 > 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數字算星座相關的資料

熱點內容
程序員在東南亞被毒打 瀏覽:284
php內存操作 瀏覽:6
1加手機號碼放哪個文件夾 瀏覽:728
大兵程序員 瀏覽:785
青桔app福利中心在哪裡 瀏覽:170
演算法安全是智能化戰爭的博弈焦點 瀏覽:497
編譯器用vs多少 瀏覽:316
pc單機游戲壓縮包下載 瀏覽:570
伺服器鎖定什麼意思 瀏覽:731
吐司解壓神器 瀏覽:70
程序員的電腦一般用什麼 瀏覽:934
如何從伺服器中查詢表是否存在 瀏覽:323
android首頁布局源碼 瀏覽:46
虎牙主播是怎麼安卓投屏的 瀏覽:782
redmonk編程語言排行榜 瀏覽:110
android嵌入html5 瀏覽:676
雲伺服器能永久使用嗎 瀏覽:904
linux安裝openresty 瀏覽:386
ubunt配置php 瀏覽:975
達達取貨碼在app哪裡 瀏覽:49