PHP | convert_cyr_string() Function

The convert_cyr_string() function is a inbuilt function in PHP. The function is used to convert a string form one Cyrillic character-set to another. Here two arguments are used such as from and to and they are of single character which represent the source and destination of Cyrillic character sets.

Some supported characters set are given below in the table :

Symbol Character set
a x-cp866
d x-cp866
i iso8859-5
k koi8-r
m x-mac-cyrillic
w windows-1251


convert_cyr_string ( string $str, string $from, string $to )

Parameter Used:

  • $str : This is the original input string, which needs to be converted. This is the mandatory parameter.
  • $from : The argument $from is of single character type which is the source of Cyrillic character set, where string should be converted. This is the mandatory parameter.
  • $to : The argument $to is of single character type which is the destination of Cyrillic character set. This is the mandatory parameter.

Return Values: The function returns the converted string from given original string.


Input : Geek .....
Output : Geek .....
Explanation : The string (Geek) convert from the
              character-set "w" (windows-1251) 
              to "a" (x-cp866).

Input : Geek hello ????????
Output : Geek hello ò.ò.ò.ò.ò.ò.ò.ò.
Explanation : The string (Geek hello ????????) convert from the
              character-set "w" (windows-1251) 
              to "k" (koi8-r).

Below program illustratre the convert_cyr_string() function.





// PHP code to illustrate the 
// convert_cyr_string() function
$str = "Geeksforgeeks æøå???øåæøå";
echo $str, "\n";
// String convert from character-set 
// "w" (windows-1251) to "k" (koi8-r)
echo convert_cyr_string($str, 'w', 'k'); 



Geeksforgeeks æøåÐ?Ð?Ð?øåæøå
Geeksforgeeks ç.ç£ç½ò.ò.ò.ç£ç½ç.ç£ç½

Note: This function is binary-safe due to when passed the binary data into functions the text and string should be manipulating .


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.