Created
February 28, 2012 16:16
-
-
Save mariano/1933411 to your computer and use it in GitHub Desktop.
Export ISO 3166-1 country codes and PHP time zones per countries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$contents = trim(file_get_contents('http://www.iso.org/iso/list-en1-semic-3.txt')); | |
if (empty($contents)) { | |
throw new \Exception('Could not get list of ISO country codes from iso.org'); | |
} | |
$countries = array(); | |
$timeZones = array(); | |
foreach(explode(PHP_EOL, $contents) as $line) { | |
if (preg_match('/^(.+?);([A-Za-z]{2})$/', trim($line), $matches)) { | |
$code = $matches[2]; | |
$countries[$code] = mb_convert_case($matches[1], MB_CASE_TITLE); | |
$timeZones[$code] = array_flip(\DateTimeZone::listIdentifiers(\DateTimeZone::PER_COUNTRY, $code)); | |
foreach($timeZones[$code] as $tz => $v) { | |
$timeZones[$code][$tz] = str_replace(array('/', '_'), array(' > ', ' '), $tz); | |
} | |
} | |
} | |
header('Content-type: text/plain'); | |
echo 'COUNTRY CODES WITHOUT TIME ZONES: ' . implode(', ', array_keys(array_diff_key($timeZones, array_filter($timeZones)))); | |
foreach(array('countries', 'timeZones') as $var) { | |
echo "\n\n"; | |
echo str_replace(' ', "\t", preg_replace('/\n*\s*array/', ' array', var_export($$var, true))); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://www.iso.org/iso/list-en1-semic-3.txt has expired