Search for:


PHP convert_cyr_string function

The convert_cyr_string() function in PHP is used to convert a string from one Cyrillic character set to another. It is mainly used for working with Cyrillic text in different encodings. Here is the basic syntax of the convert_cyr_string() function:

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


  • $str: The string to be converted.
  • $from: The source Cyrillic character set. It can be one of the following values:
    • “k” or “koi8-r”: KOI8-R (Russian) character set.
    • “w” or “windows-1251”: Windows-1251 (Windows Cyrillic) character set.
    • “i” or “iso9-ru”: ISO-8859-5 (ISO Cyrillic) character set.
  • $to: The target Cyrillic character set. It can have the same values as $from.

Return Value:

  • The converted string.

Example Usage:

$str = "Привет, мир!";
$convertedStr = convert_cyr_string($str, "w", "k");
echo $convertedStr;

In this example, the string “Привет, мир!” is converted from the Windows-1251 character set ("w") to the KOI8-R character set ("k"). The converted string is then echoed, displaying the text in the target character set.

It’s worth noting that the convert_cyr_string() function is deprecated as of PHP 7.2.0 and is not recommended for use in new projects. It’s advised to use multibyte string functions (mb_convert_encoding()) or the iconv extension for character encoding conversions in PHP.