note 74905 deleted from function.utf8-encode by cmb
| From: | cmb@php.net | Date: | Sun, 04 Dec 2016 12:12:23 +0000 |
| Subject: | note 74905 deleted from function.utf8-encode by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-208196@lists.php.net to get a copy of this message | ||
Note Submitter: nikooo adog bk adot ru - Nickolaz
----
You can use this simple code to convert win-1251 into Unicode.
function rus2uni($str,$isTo = true)
{
$arr =
array('Ñ'=>'ё','Ð'=>'Ё');
for($i=192;$i<256;$i++)
$arr[chr($i)] = ''.dechex($i-176).';';
$str =preg_replace(array('@([а-Ñ]) @i','@
([а-Ñ])@i'),array('$1 ',' $1'),$str);
return strtr($str,$isTo?$arr:array_flip($arr));
}
That is useful for xml_parser (to parse windows-1251 files like utf-8).