note 89111 deleted from function.timezone-identifiers-list by salathe
| From: | salathe@php.net | Date: | Sun, 24 Oct 2021 22:26:58 +0000 |
| Subject: | note 89111 deleted from function.timezone-identifiers-list by salathe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-217109@lists.php.net to get a copy of this message | ||
Note Submitter: david at mytton dot net
----
A better code snippet to return useful timezone information that can be used in a drop menu, for
example:
<?php
$zones = timezone_identifiers_list();
foreach ($zones as $zone)
{
$zone = explode('/', $zone); // 0 => Continent, 1 => City
// Only use "friendly" continent names
if ($zone[0] == 'Africa' || $zone[0] == 'America' || $zone[0] ==
'Antarctica' || $zone[0] == 'Arctic' || $zone[0] == 'Asia' || $zone[0]
== 'Atlantic' || $zone[0] == 'Australia' || $zone[0] == 'Europe' ||
$zone[0] == 'Indian' || $zone[0] == 'Pacific')
{
if (isset($zone[1]) != '')
{
$locations[$zone[0]][$zone[0]. '/' . $zone[1]] = str_replace('_', '
', $zone[1]); // Creates array(DateTimeZone => 'Friendly name')
}
}
}
?>
The $locations array will contain a multi-dimensional array for each continent like
Array
(
[Africa] => Array
(
[Africa/Abidjan] => Abidjan
[Africa/Accra] => Accra
[Africa/Addis_Ababa] => Addis Ababa
[Africa/Algiers] => Algiers
...
)
[America] => Array
(
[America/Adak] => Adak
[America/Anchorage] => Anchorage
[America/Anguilla] => Anguilla
...