php – convert_cyr_string function

convert_cyr_string

(PHP 3 >= 3.0.6, PHP 4, PHP 5)
convert_cyr_string — Convert from one Cyrillic character set to another
Description
string convert_cyr_string ( string str, string from, string to )

This function returns the given string converted from one Cyrillic character set to another. The from and to arguments are single characters that represent the source and target Cyrillic character sets. The supported types are:

*

k – koi8-r
*

w – windows-1251
*

i – iso8859-5
*

a – x-cp866
*

d – x-cp866
*

m – x-mac-cyrillic

Note: This function is binary-safe.

Example 1:

I wrote my own func to convert from win1251 to utf8:

<?php
function win2utf($s) {
for($i=0,$m=strlen($s);$i<$m;$i++) {
$c=ord($s[$i]);
if ($c>127) // convert only special chars
if    ($c==184)    $t.=chr(209).chr(209); // small io
elseif ($c==168)    $t.=chr(208).chr(129); // capital io
else              $t.=($c>239?chr(209):chr(208)).chr($c-48);
else $t.=$s[$i];
}
return $t;
}
?>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: