define('NL', "\n");
function hs_option($value,$content,$selected = 0)
{
if ($selected) $sel = ' selected="selected"';
else $sel = null;
return "<option value=\"$value\"$sel>$content</option>\n";
}
$now = time();
function hs_select_month($name,$def = null)
{
global $now;
if ($def === null) $def = date('m',$now);
$months = array(
'Jan','Feb','Mar','Apr','May','Jun',
'Jul','Aug','Sep','Oct','Nov','Dec');
$str = '<select name="' . $name . '">' . NL;
/* Cycle through */
$id = 1;
foreach($months as $month)
{
if ($id < 10) $idx = '0' . $id;
else $idx = $id;
if ($idx == $def) $sel = 1;
else $sel = 0;
$str .= hs_option($idx,$month,$sel);
$id++;
}
/* Finish Up */
$str .= '</select>' . NL;
return $str;
}
The hs_option makes it easier to build an option element. The hs_select_month builds a month select element. Note that for various reasons, I encode the months as '01', '02'.