如题所述
æ¹æ³ä¸ï¼
â ãæ®éå¹´è½è¢«4æ´é¤èä¸è½è¢«100æ´é¤ç为é°å¹´ãï¼å¦2004å¹´å°±æ¯é°å¹´,1900å¹´ä¸æ¯é°å¹´ï¼
â¡ãä¸çºªå¹´è½è¢«400æ´é¤èä¸è½è¢«3200æ´é¤ç为é°å¹´ã(å¦2000å¹´æ¯é°å¹´ï¼3200å¹´ä¸æ¯é°å¹´)
<?php
function is_leap($year){
if($year%100==0){//å¤æä¸çºªå¹´
if ($year%400==0&&$year%3200!=0){
return "ä¸çºªå¹´".$year."æ¯é°å¹´!";//ä¸çºªå¹´éçé°å¹´
}
else{
return "ä¸çºªå¹´".$year."ä¸æ¯é°å¹´!";
}
}
else{//å©ä¸çå°±æ¯æ®éå¹´äº
if($year%4==0&&$year%100!=0){
return "æ®éå¹´".$year."æ¯é°å¹´!";//æ®éå¹´éçé°å¹´
}
else {
return "æ®éå¹´".$year."ä¸æ¯é°å¹´!";
}
}
}
?>
æ¹æ³äºï¼
<?php
function is_leap($year){
$time = mktime(20,20,20,4,20,$year);//åå¾ä¸ä¸ªæ¥æç Unix æ¶é´æ³;
if (date("L",$time)==1){ //æ ¼å¼åæ¶é´ï¼å¹¶ä¸å¤ææ¯ä¸æ¯é°å¹´ï¼åé¢ççäºä¸ä¹å¯ä»¥çç¥ï¼
return $year."æ¯é°å¹´";
}else{
return $year."ä¸æ¯é°å¹´";
}
}
?>
æ¹æ³ä¸ï¼
<?php
function is_leap($year){
$time = mktime(20,20,20,2,1,$year);//åå¾ä¸ä¸ªæ¥æç Unix æ¶é´æ³;
if (date("t",$time)==29){ //æ ¼å¼åæ¶é´ï¼å¹¶ä¸å¤æ2ææ¯å¦æ¯29天ï¼
return $year."æ¯é°å¹´";//æ¯29天就è¾åºæ¶é°å¹´ï¼
}else{
return $year."ä¸æ¯é°å¹´";
}
}
?>
â ãæ®éå¹´è½è¢«4æ´é¤èä¸è½è¢«100æ´é¤ç为é°å¹´ãï¼å¦2004å¹´å°±æ¯é°å¹´,1900å¹´ä¸æ¯é°å¹´ï¼
â¡ãä¸çºªå¹´è½è¢«400æ´é¤èä¸è½è¢«3200æ´é¤ç为é°å¹´ã(å¦2000å¹´æ¯é°å¹´ï¼3200å¹´ä¸æ¯é°å¹´)
<?php
function is_leap($year){
if($year%100==0){//å¤æä¸çºªå¹´
if ($year%400==0&&$year%3200!=0){
return "ä¸çºªå¹´".$year."æ¯é°å¹´!";//ä¸çºªå¹´éçé°å¹´
}
else{
return "ä¸çºªå¹´".$year."ä¸æ¯é°å¹´!";
}
}
else{//å©ä¸çå°±æ¯æ®éå¹´äº
if($year%4==0&&$year%100!=0){
return "æ®éå¹´".$year."æ¯é°å¹´!";//æ®éå¹´éçé°å¹´
}
else {
return "æ®éå¹´".$year."ä¸æ¯é°å¹´!";
}
}
}
?>
æ¹æ³äºï¼
<?php
function is_leap($year){
$time = mktime(20,20,20,4,20,$year);//åå¾ä¸ä¸ªæ¥æç Unix æ¶é´æ³;
if (date("L",$time)==1){ //æ ¼å¼åæ¶é´ï¼å¹¶ä¸å¤ææ¯ä¸æ¯é°å¹´ï¼åé¢ççäºä¸ä¹å¯ä»¥çç¥ï¼
return $year."æ¯é°å¹´";
}else{
return $year."ä¸æ¯é°å¹´";
}
}
?>
æ¹æ³ä¸ï¼
<?php
function is_leap($year){
$time = mktime(20,20,20,2,1,$year);//åå¾ä¸ä¸ªæ¥æç Unix æ¶é´æ³;
if (date("t",$time)==29){ //æ ¼å¼åæ¶é´ï¼å¹¶ä¸å¤æ2ææ¯å¦æ¯29天ï¼
return $year."æ¯é°å¹´";//æ¯29天就è¾åºæ¶é°å¹´ï¼
}else{
return $year."ä¸æ¯é°å¹´";
}
}
?>
温馨提示:答案为网友推荐,仅供参考
第1个回答 2011-10-19
<?php
if($_POST['submits']){
leap($_POST['year']);
}
function leap($year) {
if ($year % 4 == 0 && $year != 0) {
echo $year . "是闰年";
} else {
echo $year . "不是闰年";
}
}
?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<input type="text" name="year" value="" size="5" maxlength="5"/>
<input type="submit" name="submits" value="提交"/>
</form>
if($_POST['submits']){
leap($_POST['year']);
}
function leap($year) {
if ($year % 4 == 0 && $year != 0) {
echo $year . "是闰年";
} else {
echo $year . "不是闰年";
}
}
?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<input type="text" name="year" value="" size="5" maxlength="5"/>
<input type="submit" name="submits" value="提交"/>
</form>