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

复制代码 代码如下:

function mdy($mid = "month", $did = "day", $yid = "year", $mval, $dval, $yval)
{
  if(empty($mval)) $mval = date("m");
  if(empty($dval)) $dval = date("d");
  if(empty($yval)) $yval = date("Y");
  $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");
  $out = "<select>";
  foreach($months as $val => $text)
    if($val == $mval) $out .= "<option value='$val' selected>$text</option>";
    else $out .= "<option value='$val'>$text</option>";
  $out .= "</select> ";
  $out .= "<select>";
  for($i = 1; $i <= 31; $i++)
    if($i == $dval) $out .= "<option value='$i' selected>$i</option>";
    else $out .= "<option value='$i'>$i</option>";
  $out .= "</select> ";
  $out .= "<select>";
  for($i = date("Y"); $i <= date("Y") + 2; $i++)
    if($i == $yval) $out.= "<option value='$i' selected>$i</option>";
    else $out.= "<option value='$i'>$i</option>";
  $out .= "</select>";
  return $out;
}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/0cc6cedac36c5a5e9cbacea7c217b194.html