I am currently getting a user's country in PHP using the following method;
Locale::getDisplayRegion($_SERVER[HTTP_ACCEPT_LANGUAGE],'en')
This returns the countries name in text e.g. United States.
However, I want to return the abbreviated country code from the $_SERVER[HTTP_ACCEPT_LANGUAGE]
request rather than the full text name. How can I do this?
The Symfony framework has a handy function for determining the preferred language based on the Accept-Language
header:
https://github.com/symfony/HttpFoundation/blob/master/Request.php#L1463
https://github.com/symfony/HttpFoundation/blob/master/Request.php#L1498