I would like to get some class to turn a full country name like United States
into a 2 letters ISO country code US
P.S. i don't prefer to call something like google API for this.
Thanks!
How about the array here?
You could then call it as follows:
$code = array_search('United States', $countrycodes); // returns 'US'
$country = $countrycodes['US']; // returns 'United States'
I made a small and growing collection of classes on github that contain constants for this purpose. you don't have to search for it and you can get hints via your IDE as your typing. Helpfull if you can't remember all the country names and spellings.
It also can do country codes to country names :P
Save this code as cc.php
include_once 'cc.php';
$iso_code = array_search(strtolower($country_that_you_want_to_convert), array_map('strtolower', $countrycodes)); ## easy version
or we can make Function like this:
Version 1:
include_once 'cc.php';
function get_iso_code($country_that_you_want_to_convert, $countrycodes){
$iso_code = array_search(strtolower($country_that_you_want_to_convert), array_map('strtolower', $countrycodes)); ## easy version
return $iso_code;
}
Version 2:
function get_iso_code($country_that_you_want_to_convert){
include_once 'cc.php';
$iso_code = array_search(strtolower($country_that_you_want_to_convert), array_map('strtolower', $countrycodes)); ## easy version
return $iso_code;
}
Sorry if I made mistakes. if got only downvote I will happy to remove my post. hope its help someone.