|
Posted by Justin Koivisto on 01/24/06 23:22
finalwebsites.com wrote:
> I have one where you can use labels in your own language:
>
> http://www.finalwebsites.com/snippets.php?id=1
>
> ;-)
OK, so I modified my version to use setlocale and strftime and now mine
does the same. ;)
<?php
/**
* Generates an HTML select element for the month. Uses strftime, so
* obeys the current (or provided) locale. If no month is supplied,
* current month is used. If 0 is passed, no month is selected.
*
* @param string $name The name of the HTML field
* @param int $this_month=-1 The month number to have selected.
* @param mixed $locale=0 The locale(s) to use. 2nd parameter to setlocale
* @return string
*/
function get_html_select_month($name='',$this_month=-1,$locale=0){
if($locale!==0){
// get current locale setting
$curr_locale=setlocale(LC_TIME,0);
// set to the passed locale
if(!setlocale(LC_TIME,$locale)){
// unable to use that locale on this system
return FALSE;
}
}
if(empty($name)) $name='month';
if($this_month==-1) $this_month=date('n');
$months=range(1,12);
$str='<select name="'.$name.'">'."\n";
foreach($months as $month){
$str.=' <option value="'.$month.'"';
if($month==$this_month) $str.=' selected="selected"';
$str.='>'.strftime('%B',mktime(0,0,0,$month,1,2006)).'</option>'."\n";
}
$str.='</select>'."\n";
if($locale!==0){
setlocale(LC_TIME,0);
}
if(isset($curr_locale)){
// set the locale back.
if(!setlocale(LC_TIME,$curr_locale)){
// this should never happen!
return FALSE;
}
}
return $str;
}
?>
--
Justin Koivisto, ZCE - justin@koivi.com
http://koivi.com
Navigation:
[Reply to this message]
|