title: Magento - Get Country Id from Name - is there a easier/quicker way?
body: <p>I need to load the 2 letter ISO2 country ID for a given country name.</p>
  
  <p>Right now, I use the following method to do this:</p>
  
  <pre><code>// Method to Get countryId from CountryName
  function getCountryId($countryName) {
      $countryId = '';
      $countryCollection = Mage::getModel('directory/country')-&gt;getCollection();
      foreach ($countryCollection as $country) {
          if ($countryName == $country-&gt;getName()) {
              $countryId = $country-&gt;getCountryId();
              break;
          }
      }
      $countryCollection = null;
      return $countryId;
  }
  </code></pre>
  
  <p>Usage:</p>
  
  <pre><code>var_dump(getCountryId('Germany'));
  </code></pre>
  
  <p>Outputs:</p>
  
  <pre><code>string(2) "DE"
  </code></pre>
  
  <p>Is there a easier/quicker way to do this instead of loading the country collection and iterating through it every time?</p>