note 106366 modified in datetimezone.listidentifiers by danbrown

From: Date: Mon, 31 Oct 2011 15:11:08 +0000
Subject: note 106366 modified in datetimezone.listidentifiers by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-184250@lists.php.net to get a copy of this message
I normaly use this script to allow the user choose his timezone: <?php ///timezones functions function get_timezones() { if (method_exists('DateTimeZone','listIdentifiers')) { $timezones = array(); $timezone_identifiers = DateTimeZone::listIdentifiers(); foreach( $timezone_identifiers as $value ) { if ( preg_match( '/^(America|Antartica|Arctic|Asia|Atlantic|Europe|Indian|Pacific)\//', $value ) ) { $ex=explode('/',$value);//obtain continent,city $city = isset($ex[2])? $ex[1].' - '.$ex[2]:$ex[1];//in case a timezone has more than one $timezones[$ex[0]][$value] = $city; } } return $timezones; } else//old php version { return FALSE; } } function get_select_timezones($select_name='TIMEZONE',$selected=NULL) { $timezones = get_timezones(); $sel.='<select id="'.$select_name.'" name="'.$select_name.'">'; foreach( $timezones as $continent=>$timezone ) { $sel.= '<optgroup label="'.$continent.'">'; foreach( $timezone as $city=>$cityname ) { if ($selected==$city) { $sel.= '<option selected=selected value="'.$city.'">'.$cityname.'</option>'; } else $sel.= '<option value="'.$city.'">'.$cityname.'</option>'; } $sel.= '</optgroup>'; } $sel.='</select>'; return $sel; } ?> --was-- I normaly use this script to allow the user choose his timezone: ///timezones functions function get_timezones() { if (method_exists('DateTimeZone','listIdentifiers')) { $timezones = array(); $timezone_identifiers = DateTimeZone::listIdentifiers(); foreach( $timezone_identifiers as $value ) { if ( preg_match( '/^(America|Antartica|Arctic|Asia|Atlantic|Europe|Indian|Pacific)\//', $value ) ) { $ex=explode('/',$value);//obtain continent,city $city = isset($ex[2])? $ex[1].' - '.$ex[2]:$ex[1];//in case a timezone has more than one $timezones[$ex[0]][$value] = $city; } } return $timezones; } else//old php version { return FALSE; } } function get_select_timezones($select_name='TIMEZONE',$selected=NULL) { $timezones = get_timezones(); $sel.='<select id="'.$select_name.'" name="'.$select_name.'">'; foreach( $timezones as $continent=>$timezone ) { $sel.= '<optgroup label="'.$continent.'">'; foreach( $timezone as $city=>$cityname ) { if ($selected==$city) { $sel.= '<option selected=selected value="'.$city.'">'.$cityname.'</option>'; } else $sel.= '<option value="'.$city.'">'.$cityname.'</option>'; } $sel.= '</optgroup>'; } $sel.='</select>'; return $sel; } http://php.net/manual/en/datetimezone.listidentifiers.php

« previous php.notes (#184250) next »