Open In App

PHP | convert_cyr_string() Function

Last Updated : 30 Mar, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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

  • $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.

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
 
// 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


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads