note 98537 deleted from datetimezone.listidentifiers by danbrown
| From: | danbrown@php.net | Date: | Tue, 22 Jun 2010 00:02:01 +0000 |
| Subject: | note 98537 deleted from datetimezone.listidentifiers by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-170358@lists.php.net to get a copy of this message | ||
Note Submitter: mike at macgirvin dot com
----
The function from chema is missing some notable entries (Australia, Canada, Brazil) and returns
incorrect values for Indiana, among other issues (unable to use Navajo).
This is slightly more complicated but allows any legal entry to be used.
<?php
function cmp($a, $b) {
if(strstr($a,'/') && strstr($b,'/')) {
if ($a == $b) {
return 0;
}
return ($a < $b) ? -1 : 1;
}
if(strstr($a,'/'))
return -1;
if(strstr($b,'/'))
return 1;
if ($a == $b) {
return 0;
}
return ($a < $b) ? -1 : 1;
}
?>
<select id="TIMEZONE" name="TIMEZONE">
<?php
$timezone_identifiers = DateTimeZone::listIdentifiers();
usort($timezone_identifiers, 'cmp');
$continent = '';
foreach($timezone_identifiers as $value) {
$ex = explode("/", $value);
if(count($ex) > 1) {
if($ex[0] != $continent) {
if($continent != '')
echo '</optgroup>';
$continent = $ex[0];
echo "<optgroup label=\"$continent\">";
}
if(count($ex) > 2)
$city = substr($value,strpos($value,'/')+1);
else
$city = $ex[1];
}
else {
$city = $ex[0];
if($continent != 'Miscellaneous') {
echo '</optgroup>';
$continent = 'Miscellaneous';
echo "<optgroup label=\"$continent\">";
}
}
echo '<option
value="'.$value.'">'.$city.'</option>';
}
?>
</optgroup>
</select>