Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to recognize user language in PHP

Is there any way to parse the HTTP_USER_AGENT to get the current user language ?

like image 519
Galileox86 Avatar asked Feb 13 '26 19:02

Galileox86


2 Answers

Try:

$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
echo $lang;
like image 117
Sarfraz Avatar answered Feb 15 '26 16:02

Sarfraz


You may want to try HTTP_ACCEPT_LANGUAGE in the $_SERVER superglobal.

Take a look at http://php.net/manual/en/reserved.variables.server.php for more information.

This will return a value like 'en-us' which you can then break down as needed.

like image 38
sparkey0 Avatar answered Feb 15 '26 18:02

sparkey0



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!