Obtenir idioma del navegador


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function getIdiomaNavegador ()
  2. {
  3. if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"]))
  4. {
  5. $idiomes = explode(",", $_SERVER["HTTP_ACCEPT_LANGUAGE"]);
  6. for($i = 0;$i < count($idiomes);$i++)
  7. {
  8. if (strlen($idiomes[$i]) > 2) $idiomes[$i] = substr($idiomes[$i], 0, 2);
  9. if (in_array($idiomes[$i], $this->IDIOMES_COMPARTIR))
  10. {
  11. $idioma = array_keys($this->IDIOMES_COMPARTIR, $idiomes[$i]);
  12. return ($idioma[0] + 1);
  13. }
  14. }
  15. }
  16. return 1;

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.