note 76192 added to function.timezone-identifiers-list

From: Date: Wed, 04 Jul 2007 13:22:34 +0000
Subject: note 76192 added to function.timezone-identifiers-list
Groups: php.notes 
Request: Send a blank email to php-notes+get-128224@lists.php.net to get a copy of this message
Hi! Since many are going to use these timezones for saving their users' timezones, I wrote a little something that builds the select-field for this purpose and removes the "Others" that are not supposed to be used. Note that <optgroup> is not widely supported and causes a bug in Opera 6. I know this is easy to do, but you need to examine the timezones first (for example to remember that Istanbul is in the category for two continents - of course). <select name="timezonechoice" size="10"><?php function timezonechoice($selectedzone) { $all = timezone_identifiers_list(); $i = 0; foreach($all AS $zone) { $zone = explode('/',$zone); $zonen[$i]['continent'] = $zone[0]; $zonen[$i]['city'] = $zone[1]; $i++; } asort($zonen); foreach($zonen AS $zone) { extract($zone); if($continent == 'Africa' OR $continent == 'America' OR $continent == 'Antarctica' OR $continent == 'Arctic' OR $continent == 'Asia' OR $continent == 'Atlantic' OR $continent == 'Australia' OR $continent == 'Europe' OR $continent == 'Indian' OR $continent == 'Pacific') { if(!isset($letztercontinent)) $structure .= ' <optgroup label="'.$continent.'">'; // continent elseif($letztercontinent!=$continent) $structure .= '</optgroup> <optgroup label="'.$continent.'">'; // continent if($city!='') $structure .= " <option ".((($continent.'/'.$city)==$selectedzone)?'selected="selected "':'')." value=\"".($continent.'/'.$city)."\">".str_replace('_',' ',$city)."</option>"; //Timezone else $structure .= " <option ".(($continent==$selectedzone)?'selected="selected "':'')." value=\"".$continent."\">".$continent."</option>"; //Timezone $letztercontinent = $continent; } } $structure .= ' </optgroup>'; return $structure; } echo timezonechoice('Europe/Berlin'); ?></select> Hope this saves someone some effort. ---- Server IP: 193.190.198.20 Probable Submitter: 213.219.186.129 ---- Manual Page -- http://www.php.net/manual/en/function.timezone-identifiers-list.php Edit -- https://master.php.net/note/edit/76192 Del: integrated -- https://master.php.net/note/delete/76192/integrated Del: useless -- https://master.php.net/note/delete/76192/useless Del: bad code -- https://master.php.net/note/delete/76192/bad+code Del: spam -- https://master.php.net/note/delete/76192/spam Del: non-english -- https://master.php.net/note/delete/76192/non-english Del: in docs -- https://master.php.net/note/delete/76192/in+docs Del: other reasons-- https://master.php.net/note/delete/76192 Reject -- https://master.php.net/note/reject/76192 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#128224) next »