Created
December 27, 2013 05:40
-
-
Save LastDragon-ru/8143002 to your computer and use it in GitHub Desktop.
Convert ISO 3166-1 Alpha-2 into php code
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
<pre> | |
<?php | |
/** | |
* @see http://www.iso.org/iso/home/standards/country_codes.htm | |
* @author Aleksey Lebedev aka LastDragon <[email protected]> | |
* @license BSD license | |
*/ | |
$file = 'http://www.iso.org/iso/home/standards/country_codes/country_names_and_code_elements_txt.htm'; | |
$data = file($file); | |
$delimiter = ';'; | |
if (!$data || count($data) <= 1) { | |
echo 'File does not exist or is empty :('; | |
} | |
array_shift($data); | |
foreach ($data as $line) { | |
list ($name, $code) = str_getcsv($line, $delimiter) + array(null, null); | |
if ($name && $code) { | |
$name = addslashes(iconv('UTF-8', 'ASCII//TRANSLIT', $name)); | |
$code = strtoupper($code); | |
echo "const COUNTRY_{$code} = '{$name}';\n"; | |
} | |
} | |
?> | |
</pre> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment