Guest User

Untitled

a guest
Apr 24th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. /**
  2. * Set locale in a platform-independent way
  3. * @param string $locale the locale name ('en_US', 'uk_UA', 'fr_FR' etc)
  4. * @return string the encoding name used by locale-aware functions
  5. * @throw Exception if the locale could not be set
  6. */
  7. function setLocaleCP($locale) {
  8. list($lang, $cty) = explode('_', $locale);
  9. $locales = array($locale . '.UTF-8', $lang);
  10. $result = setlocale(LC_ALL, $locales);
  11.  
  12. if(!$result) {
  13. throw new Exception("Unknown Locale name $locale");
  14. }
  15.  
  16. // See if we have successfully set it to UTF-8
  17. if(!strpos($result, 'UTF-8')) {
  18. preg_match('~\.(\d+)$~', $result, $m);
  19. $encoding = 'CP' . $m[1];
  20. } else {
  21. $encoding = 'UTF-8';
  22. }
  23.  
  24. return $encoding;
  25. }
Add Comment
Please, Sign In to add comment