Magento : Get country code by country name

magento, php

Solution

From the other question, this can only be done by looping through the country collection

$countryId = '';
$countryCollection = Mage::getModel('directory/country')->getCollection();
foreach ($countryCollection as $country) {
    if ($countryName == $country->getName()) {
        $countryId = $country->getCountryId();
        break;
    }
}
echo $countryId;

Because of how the data is stored in the XML there is no way to filter or load by name.

Problem

I have tried to find country code by country name. So, for example, I have "Netherlands", I need to get "NL" I know there is method to find name form code: ``` $country_name = Mage::app()->getLocale()->getCountryTranslation($country_code) ``` But I need vice versa. So is there any methods in Magento to resolve it?

Original source

Related problems