Skip to content

Instantly share code, notes, and snippets.

@pafnuty
Created June 7, 2014 04:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pafnuty/df8902ea255dc77fc304 to your computer and use it in GitHub Desktop.
Save pafnuty/df8902ea255dc77fc304 to your computer and use it in GitHub Desktop.
Костыль для 1251
<?
/**
* Функция конвертирует utf8 в 1251
* @param $arr
* @param $charset
*
* @return array|object|string
*/
function iconv_1251($arr, $charset) {
if ($charset == 'windows-1251') {
return $arr;
}
$returnObj = false;
if (is_object($arr)) {
$arr = (array)$arr;
$returnObj = true;
}
if (is_array($arr)) {
$returnArr = array_map('iconv_1251', $arr);
}
else {
$returnArr = iconv('UTF-8', 'WINDOWS-1251', $arr);
}
return ($returnObj) ? (object)$returnArr : $returnArr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment