note 79237 deleted from function.timezone-identifiers-list by derick

From: Date: Tue, 13 May 2008 20:16:13 +0000
Subject: note 79237 deleted from function.timezone-identifiers-list by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-139356@lists.php.net to get a copy of this message
Note Submitter: vats_tco at comcast dot net ---- Your script was useful, thanks. I made a few small changes to the script to make it work and display the Time Zones properly. The list would display the cities by country but some cities have sub-cities that are not displayed so you would see 8 Argentina's for example and the value would not get the proper Time Zone. With this fix it will display the sub-cites and add them to the value as well. <?php function get_tz_options($selectedzone, $label, $desc = '') { echo '<div class="label"><label for="edited_user_timezone">'.$label.':</label></div>'; echo '<div class="input"><select name="edited_user_timezone">'; 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]; $zonen[$i]['subcity'] = $zone[2]; $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($selectcontinent)) { $structure .= '<optgroup label="'.$continent.'">'; // continent } elseif($selectcontinent != $continent) { $structure .= '</optgroup><optgroup label="'.$continent.'">'; // continent } if($city != ''){ if ($subcity != ''){ $city = $city . '/'. $subcity; } $structure .= "<option ".((($continent.'/'.$city)==$selectedzone)?'selected="selected "':'')." value=\"".($continent.'/'.$city)."\">".str_replace('_',' ',$city)."</option>"; //Timezone } else { if ($subcity != ''){ $city = $city . '/'. $subcity; } $structure .= "<option ".(($continent==$selectedzone)?'selected="selected "':'')." value=\"".$continent."\">".$continent."</option>"; //Timezone } $selectcontinent = $continent; } } $structure .= '</optgroup>'; return $structure; } echo timezonechoice($selectedzone); echo '</select>'; echo '<span class="notes"> '.$desc.' </span></div>'; } ?>

« previous php.notes (#139356) next »