Open In App

PHP | convert_cyr_string() Function

The convert_cyr_string() function is a inbuilt function in PHP. The function is used to convert a string from 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

Syntax:  

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

Parameter Used



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

Examples:  

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 illustrate the convert_cyr_string() function.  




<?php
 
// 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');
 
?>

Output

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

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

Reference: http://php.net/manual/en/function.convert-cyr-string.php

Article Tags :