Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Set locale in a platform-independent way
- * @param string $locale the locale name ('en_US', 'uk_UA', 'fr_FR' etc)
- * @return string the encoding name used by locale-aware functions
- * @throw Exception if the locale could not be set
- */
- function setLocaleCP($locale) {
- list($lang, $cty) = explode('_', $locale);
- $locales = array($locale . '.UTF-8', $lang);
- $result = setlocale(LC_ALL, $locales);
- if(!$result) {
- throw new Exception("Unknown Locale name $locale");
- }
- // See if we have successfully set it to UTF-8
- if(!strpos($result, 'UTF-8')) {
- preg_match('~\.(\d+)$~', $result, $m);
- $encoding = 'CP' . $m[1];
- } else {
- $encoding = 'UTF-8';
- }
- return $encoding;
- }
Add Comment
Please, Sign In to add comment