title: How to get a Facebook user's current country?
body: <p>The Facebook Graph API provides a user's <a href="http://developers.facebook.com/docs/reference/api/user/" rel="nofollow">current location</a> in two formats: name and ID. ID can be something like <em>104022926303756</em>. Name can be something like <em>Palo Alto, California</em> or <em>Beijing, China</em>. From these two fields, how do I extract the country? All American locations are in the form <code>[City], [State]</code> whereas all non-American locations are in the form <code>[City], [Country]</code>. Can I code something less hacky than:</p>
  
  <pre><code>$states = array(
   'Alabama'
   'Alaska',
   'Arizona',
   // ...
  );
  
  $country = 'USA';
  if (!in_array($locationName, $states)) {
      preg_match('#, ([a-z]+$)#i', $locationName, $match);
      $country = $match[1];
  }
  </code></pre>