Reply to Re: Populating "Month" Dropdown Menu

Your name:

Reply:


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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация