Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Generate a list of timezones with PHP
http://www.php.net/manual/en/function.timezone-identifiers-list.php
<?php
$zones = timezone_identifiers_list();
foreach ($zones as $zone)
{
$zoneExploded = explode('/', $zone); // 0 => Continent, 1 => City
// Only use "friendly" continent names
if ($zoneExploded[0] == 'Africa' || $zoneExploded[0] == 'America' || $zoneExploded[0] == 'Antarctica' || $zoneExploded[0] == 'Arctic' || $zoneExploded[0] == 'Asia' || $zoneExploded[0] == 'Atlantic' || $zoneExploded[0] == 'Australia' || $zoneExploded[0] == 'Europe' || $zoneExploded[0] == 'Indian' || $zoneExploded[0] == 'Pacific')
{
if (isset($zoneExploded[1]) != '')
{
$area = str_replace('_', ' ', $zoneExploded[1]);
if (!empty($zoneExploded[2]))
{
$area = $area . ' (' . str_replace('_', ' ', $zoneExploded[2]) . ')';
}
$locations[$zoneExploded[0]][$zone] = $area; // 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
...
@arturmamedov

This comment has been minimized.

Copy link

@arturmamedov arturmamedov commented May 8, 2013

Thanks work for me, i just do some changes for work in Smarty :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment