thiago_db

idioma php

Mar 6th, 2016
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. function idioma() {
  2. $http_accept = getenv('HTTP_ACCEPT_LANGUAGE');
  3.  
  4. if (isset($http_accept) && strlen($http_accept) > 1) {
  5. $x = explode(",", $http_accept);
  6. foreach ($x as $val) {
  7. if (preg_match("/(.*);q=([0-1]{0,1}.d{0,4})/i", $val, $matches))
  8. $lang[$matches[1]] = (float) $matches[2];
  9. else
  10. $lang[$val] = 1.0;
  11. }
  12.  
  13. $qval = 0.0;
  14. foreach ($lang as $key => $value) {
  15. if ($value > $qval) {
  16. $qval = (float) $value;
  17. return $key;
  18. }
  19. }
  20. }
  21. return self::$tag_default;
  22. }
  23.  
  24. switch (idioma()) {
  25. case "pt-BR":
  26. case "pt": header('Location: http://pt.dominio.com');
  27. break;
  28. case 'en-us': header('Location: index.php');
  29. break;
  30. case 'es': header('Location: http://es.dominio.com');
  31. break;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment