note 98537 added to datetimezone.listidentifiers
| From: | mike at macgirvin dot com | Date: | Tue, 22 Jun 2010 00:00:54 +0000 |
| Subject: | note 98537 added to datetimezone.listidentifiers | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-170357@lists.php.net to get a copy of this message | ||
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>
----
Server IP: 117.104.162.229
Probable Submitter: 150.101.202.72 (proxied: 150.101.202.72)
----
Manual Page -- http://www.php.net/manual/en/datetimezone.listidentifiers.php
Edit -- https://master.php.net/note/edit/98537
Del: integrated -- https://master.php.net/note/delete/98537/integrated
Del: useless -- https://master.php.net/note/delete/98537/useless
Del: bad code -- https://master.php.net/note/delete/98537/bad+code
Del: spam -- https://master.php.net/note/delete/98537/spam
Del: non-english -- https://master.php.net/note/delete/98537/non-english
Del: in docs -- https://master.php.net/note/delete/98537/in+docs
Del: other reasons-- https://master.php.net/note/delete/98537
Reject -- https://master.php.net/note/reject/98537
Search -- https://master.php.net/manage/user-notes.php