php生成年月日下载列表的方法

这篇文章主要介绍了php生成年月日下载列表的方法,涉及php操作日期的相关技巧,非常具有实用价值,需要的朋友可以参考下.

本文实例讲述了php生成年月日下载列表的方法,分享给大家供大家参考,具体实现方法如下:

  1. function mdy($mid = "month", $did = "day", $yid = "year", $mval, $dval, $yval)
  2. {
  3. if(emptyempty($mval)) $mval = date("m");
  4. if(emptyempty($dval)) $dval = date("d");
  5. if(emptyempty($yval)) $yval = date("Y");
  6. $months = array(1 => "January", 2 => "February", 3 => "March", 4 => "April", 5 => "May", 6 => "June", 7 => "July", 8 => "August", 9 => "September", 10 => "October", 11 => "November", 12 => "December");
  7. $out = "<select name='$mid' >";
  8. foreach($months as $val => $text)
  9. if($val == $mval) $out .= "<option value='$val' selected>$text</option>";
  10. else $out .= "<option value='$val'>$text</option>";
  11. $out .= "</select> ";
  12. $out .= "<select name='$did' >";
  13. for($i = 1; $i <= 31; $i++)
  14. if($i == $dval) $out .= "<option value='$i' selected>$i</option>";
  15. else $out .= "<option value='$i'>$i</option>";
  16. $out .= "</select> ";
  17. $out .= "<select name='$yid' >";
  18. for($i = date("Y"); $i <= date("Y") + 2; $i++)
  19. if($i == $yval) $out.= "<option value='$i' selected>$i</option>";
  20. else $out.= "<option value='$i'>$i</option>";
  21. $out .= "</select>";
  22. return $out;
  23. }