PHP----------php根據生日(時間戳)計算星座


/**
 * 根據時間戳計算星座
 * @param $time
 * @return mixed
 */
function get_constellation($time)
{
    $y   = date("Y").'-';
    $his = ' 00:00:00';
    $birth_month = date("m", $time);
    $birth_date  = date("d", $time);

    $userTime = strtotime($y.$birth_month.'-'.$birth_date.$his);

    $januaryS   = strtotime($y.'01-20'.$his);
    $januaryE   = strtotime($y.'02-18'.$his);
    $februaryS  = strtotime($y.'02-19'.$his);
    $februaryE  = strtotime($y.'03-20'.$his);
    $marchS     = strtotime($y.'03-21'.$his);
    $marchE     = strtotime($y.'04-19'.$his);
    $aprilS     = strtotime($y.'04-20'.$his);
    $aprilE     = strtotime($y.'05-20'.$his);
    $mayS       = strtotime($y.'05-21'.$his);
    $mayE       = strtotime($y.'06-21'.$his);
    $juneS      = strtotime($y.'06-22'.$his);
    $juneE      = strtotime($y.'07-22'.$his);
    $julyS      = strtotime($y.'07-23'.$his);
    $julyE      = strtotime($y.'08-22'.$his);
    $augustS    = strtotime($y.'08-23'.$his);
    $augustE    = strtotime($y.'09-22'.$his);
    $septemberS = strtotime($y.'09-23'.$his);
    $septemberE = strtotime($y.'10-23'.$his);
    $octoberS   = strtotime($y.'10-24'.$his);
    $octoberE   = strtotime($y.'11-22'.$his);
    $novemberS  = strtotime($y.'11-23'.$his);
    $novemberE  = strtotime($y.'12-21'.$his);

    if($userTime >= $januaryS && $userTime <= $januaryE){
        $constellation = '水瓶座';
    }elseif($userTime >= $februaryS && $userTime <= $februaryE){
        $constellation = '雙魚座';
    }elseif($userTime >= $marchS && $userTime <= $marchE){
        $constellation = '白羊座';
    }elseif($userTime >= $aprilS && $userTime <= $aprilE){
        $constellation = '金牛座';
    }elseif($userTime >= $mayS && $userTime <= $mayE){
        $constellation = '雙子座';
    }elseif($userTime >= $juneS && $userTime <= $juneE){
        $constellation = '巨蟹座';
    }elseif($userTime >= $julyS && $userTime <= $julyE){
        $constellation = '獅子座';
    }elseif($userTime >= $augustS && $userTime <= $augustE){
        $constellation = '處女座';
    }elseif($userTime >= $septemberS && $userTime <= $septemberE){
        $constellation = '天秤座';
    }elseif($userTime >= $octoberS && $userTime <= $octoberE){
        $constellation = '天蠍座';
    }elseif($userTime >= $novemberS && $userTime <= $novemberE){
        $constellation = '射手座';
    }else{
        $constellation = '摩羯座';
    }

    return $constellation;
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM