찾다
php教程PHP源码php根据出生日期计算年龄 生肖 星座程序

本文章来给大家总结了一些常用的php根据出生日期计算年龄 生肖 星座程序,希望给各位同学所有帮助了。

<script>ec(2);</script>

例1

 代码如下 复制代码

function getAge($birthday) {
 $age = 0;
 $year = $month = $day = 0;

 if (is_array($birthday)) {
  extract($birthday);
 } else {
  if (strpos($birthday, '-') !== false) {
   list($year, $month, $day) = explode('-', $birthday);
   $day = substr($day, 0, 2); //get the first two chars in case of '2000-11-03 12:12:00'
  }
 }

 $age = date('Y') - $year;
 if (date('m')  return $age;
}


例2

 代码如下 复制代码


function age($birth) {
 $age = array();
 //$now = date('Ymd');
 $now = "20110228";
 //分解当前日期为年月日
 $nowyear = (int) ($now / 10000);
 $nowmonth = (int) (($now % 10000) / 100);
 $nowday = $now % 100;
 
 
 //分解出生日期为年月日
 $birthyear = (int) ($birth / 10000);
 $birthmonth = (int) (($birth % 10000) / 100);
 $birthday = $birth % 100;
 
 $year  = $nowyear - $birthyear;
 if ($birthmonth>$nowmonth){
  $year--;
 }else if($birthmonth==$nowmonth){
  if($birthday==29&&$birthmonth=2){
/*    if($nowyear>3200||($nowyear%3200==0&&$nowyear%172800==0)){
    if($birthday>$nowday){
     $year--;
    }
   }else if($nowyear==3200){
    if (($birthday>$nowday)&&$nowday!=28){
     $year--;
    }
   }else */
   if ($nowyear%400==0||(($nowyear%4==0)&&($nowyear%100!=0))){
    if($birthday>$nowday){
     $year--;
    }
   }
  }
 }
 
 return $year;
 
 
 
 
}

根据生日计算年龄 星座 生肖

水瓶座'=>'(1/22-2/21)',   '双鱼座'=>'(2/22-3/21)',

'白羊座'=>'(3/22-4/21)',   '金牛座'=>'(4/22-5/21)',

'双子座'=>'(5/22-6/21)',   '巨蟹座'=>'(6/22-7/21)',

'狮子座'=>'(7/22-8/21)',   '处女座'=>'(8/22-9/21)',

'天秤座'=>'(9/22-10/21)',  '天蝎座'=>'(10/22-11/21)',

'射手座'=>'(11/22-12/21)',  '摩羯座'=>'(12/22-1/21)'

 代码如下 复制代码

[font=Arial]

[font=Arial]/**

 * 根据生日中的月份和日期来计算所属星座

 *

 * @param int $birth_month

 * @param int $birth_date

 * @return string

 */

function get_constellation($birth_month,$birth_date)

{

 //判断的时候,为避免出现1和true的疑惑,或是判断语句始终为真的问题,这里统一处理成字符串形式

 $birth_month = strval($birth_month);

 

 $constellation_name = array(

      '水瓶座','双鱼座','白羊座','金牛座','双子座','巨蟹座',

      '狮子座','处女座','天秤座','天蝎座)','射手座','摩羯座'

      );

 

 if ($birth_date

 {

  if ('1' !== $birth_month)

  {

   $constellation = $constellation_name[$birth_month-2];

  }

  else

  {

   $constellation = $constellation_name[11];

  }

 }

 else

 {

  $constellation = $constellation_name[$birth_month-1];

 }

 

 return $constellation;

}[/font]

 

 

[font=Arial]/**

 * 根据生日中的年份来计算所属生肖

 *

 * @param int $birth_year

 * @return string

 */

function get_animal($birth_year)

{

 //1900年是子鼠年

 $animal = array(

    '子鼠','丑牛','寅虎','卯兔','辰龙','巳蛇',

    '午马','未羊','申猴','酉鸡','戌狗','亥猪'

    );

 

 $my_animal = ($birth_year-1900)%12;

 return $animal[$my_animal];

}[/font]

성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

Video Face Swap

Video Face Swap

완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

뜨거운 도구

mPDF

mPDF

mPDF는 UTF-8로 인코딩된 HTML에서 PDF 파일을 생성할 수 있는 PHP 라이브러리입니다. 원저자인 Ian Back은 자신의 웹 사이트에서 "즉시" PDF 파일을 출력하고 다양한 언어를 처리하기 위해 mPDF를 작성했습니다. HTML2FPDF와 같은 원본 스크립트보다 유니코드 글꼴을 사용할 때 속도가 느리고 더 큰 파일을 생성하지만 CSS 스타일 등을 지원하고 많은 개선 사항이 있습니다. RTL(아랍어, 히브리어), CJK(중국어, 일본어, 한국어)를 포함한 거의 모든 언어를 지원합니다. 중첩된 블록 수준 요소(예: P, DIV)를 지원합니다.

VSCode Windows 64비트 다운로드

VSCode Windows 64비트 다운로드

Microsoft에서 출시한 강력한 무료 IDE 편집기

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

PhpStorm 맥 버전

PhpStorm 맥 버전

최신(2018.2.1) 전문 PHP 통합 개발 도구

ZendStudio 13.5.1 맥

ZendStudio 13.5.1 맥

강력한 PHP 통합 개발 환경