Skip to content

convert_cyr_string()

Note: convert_cyr_string() was removed in PHP 8.0. It is a legacy function that should not be used in modern PHP applications. For converting between character encodings, use mb_convert_encoding() or iconv() instead.

The convert_cyr_string() function was historically used to convert a string from one legacy Cyrillic character set to another. The syntax of the convert_cyr_string() function was as follows:

The PHP syntax of the convert_cyr_string()

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

The function took three parameters: the string to be converted ($str), the character set to convert from ($from), and the character set to convert to ($to). The convert_cyr_string() function returned the converted string.

Here is an example of how the function was used:

Example of PHP convert_cyr_string()

php
<?php
$string = "Текст на русском";
$converted_string = convert_cyr_string($string, "w", "k");
echo $converted_string;
?>

In this example, the string is treated as being in the w character set (Windows-1251), which was historically used for Cyrillic text. We convert it to the k character set (KOI8-R). We pass the string, w, and k to the convert_cyr_string() function, which returns the converted string.

The output of this code in a modern UTF-8 environment will be garbled text (mojibake), because the raw bytes are reinterpreted without proper encoding context:


console
╨Т╨╡╨║╨╕╨▓ ╨╧╨░╨╣╨▓╨╕╨▓

As you can see, the function converted the raw bytes, but without matching the environment's encoding, it does not render as readable Cyrillic text.

Here is another historical example using the i character set (ISO 8859-5):

how to use PHP convert_cyr_string()?

php
<?php
$string = "Текст на русском";
$converted_string = convert_cyr_string($string, "w", "i");
echo $converted_string;
?>

In this example, we convert the string to the i character set. We pass the string, w, and i to the convert_cyr_string() function, which returns the converted string.

The output of this code in a modern UTF-8 environment will similarly produce garbled output:


console
╨Т╨╡╨║╨╕╨▓ ╨╧╨░╨╣╨▓╨╕╨▓

The convert_cyr_string() function is a legacy tool that is no longer maintained. Modern PHP development relies on UTF-8 by default, and legacy encoding functions like this are obsolete. For reliable character set conversion, use mb_convert_encoding() or iconv() with explicit UTF-8 targets.

We hope this article has been helpful in understanding the historical context of the convert_cyr_string() function in PHP. If you have any questions or comments, please feel free to reach out to us.

Practice

What does the PHP 'iconv' function do as described in the article?

Do you find this helpful?

Dual-run preview — compare with live Symfony routes.