note 25475 added to function.convert-cyr-string
| From: | mitya at alesh dot ru | Date: | Wed, 25 Sep 2002 07:21:04 +0000 |
| Subject: | note 25475 added to function.convert-cyr-string | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-37222@lists.php.net to get a copy of this message | ||
there is a little script that convert utf to cp1251
<?php
function u8($win,$h,$t) {
global $w8;
$w8[chr($h).chr($t)] = $win;
}
$c1 = chr(208);
$c2 = chr(209);
u8("é",208,185); u8("ö",209,134); u8("ó",209,131);
u8("ê",208,186); u8("å",208,181); u8("í",208,189);
u8("ã",208,179); u8("ø",209,136); u8("ù",209,137);
u8("ç",208,183); u8("õ",209,133); u8("ú",209,138);
u8("ô",209,132); u8("û",209,139); u8("â",208,178);
u8("à",208,176); u8("ï",208,191); u8("ð",209,128);
u8("î",208,190); u8("ë",208,187); u8("ä",208,180);
u8("æ",208,182); u8("ý",209,141); u8("ÿ",209,143);
u8("÷",209,135); u8("ñ",209,129); u8("ì",208,188);
u8("è",208,184); u8("ò",209,130); u8("ü",209,140);
u8("á",208,177); u8("þ",209,142); u8("É",208,153);
u8("Ö",208,166); u8("Ó",208,163); u8("Ê",208,154);
u8("Å",208,149); u8("Í",208,157); u8("Ã",208,147);
u8("Ø",208,168); u8("Ù",208,169); u8("Ç",208,151);
u8("Õ",208,165); u8("Ú",208,170); u8("Ô",208,164);
u8("Û",208,171); u8("Â",208,146); u8("À",208,144);
u8("Ï",208,159); u8("Ð",208,160); u8("Î",208,158);
u8("Ë",208,155); u8("Ä",208,148); u8("Æ",208,150);
u8("Ý",208,173); u8("ß",208,175); u8("×",208,167);
u8("Ñ",208,161); u8("Ì",208,156); u8("È",208,152);
u8("Ò",208,162); u8("Ü",208,172); u8("Á",208,145);
u8("Þ",208,174); u8("¸",209,145); u8("¨",208,129);
function utf2win ($text) {
global $c1,$c2,$w8;
$u = false;
$temp = "";
for($i=0,$len=strlen($text); $i<$len; $i++) {
$c = substr($text,$i,1);
if ($u) {
$c = $w8[$lc.$c];
$temp .= isset($c)?$c:"?";
$u = false;
}
else if ($c==$c1 || $c==$c2) {
$u = true;
$lc = $c;
}
else
$temp .= $c;
}
return $temp;
}
$text = file("utf8.txt");
foreach($text as $line)
echo "<br>".utf2win($line);
?>
how it works you can see on http://www.alesh.ru/lj
But there is another function iconv() (http://php.net/iconv) but not all hosters support iconv
--
http://www.php.net/manual/en/function.convert-cyr-string.php
http://master.php.net/manage/user-notes.php?action=edit+25475
http://master.php.net/manage/user-notes.php?action=delete+25475
http://master.php.net/manage/user-notes.php?action=reject+25475