(hex of Windows-1251 bytes — depends on input)
On PHP 8+: Fatal error — Call to undefined function convert_cyr_string()
How It Works
Start with KOI8-R bytes. The source must already match "k".
Pick destination "w". That means Windows-1251.
Convert. Returns a new byte string in the target encoding.
PHP 8 warning. This call is undefined on current PHP — migrate to Example 3.
Example 2 — Guard Before Calling
Detect removal safely so tutorials and apps fail gracefully.
PHP
<?php
if (!function_exists("convert_cyr_string")) {
echo "convert_cyr_string() is not available.\n";
echo "Use iconv() or mb_convert_encoding() instead.\n";
exit(0);
}
echo "Legacy function is available on this PHP build.\n";
Output
convert_cyr_string() is not available.
Use iconv() or mb_convert_encoding() instead.
How It Works
Ask PHP.function_exists checks the current runtime.
PHP 8 path. The function is missing → print guidance and exit cleanly.
Older PHP path. You could call the legacy converter after this guard.
Teaching value. Always version-check removed APIs in shared samples.
Example 3 — Modern Replacement with iconv()
Same intent as convert_cyr_string($str, "k", "w"), using full charset names.
(hex of Windows-1251 bytes — depends on input)
Works on current PHP when the iconv extension is enabled
How It Works
Use full names."KOI8-R" and "Windows-1251" replace letters k / w.
Call iconv. Converts from source encoding to destination.
Check failure.false means bad bytes or missing support.
Optional mbstring.mb_convert_encoding is the other common modern API.
Frequently Asked Questions
convert_cyr_string() converts a string between legacy Cyrillic single-byte encodings such as KOI8-R, Windows-1251, and ISO-8859-5. You pass the byte string plus one-character source and destination charset codes.
string convert_cyr_string(string $str, string $from, string $to). The $from and $to parameters are single letters for encodings (for example "k" for KOI8-R and "w" for Windows-1251).
No. It was deprecated in PHP 7.4 and removed in PHP 8.0. Use iconv() or mb_convert_encoding() in modern PHP.
k = KOI8-R, w = Windows-1251, i or d = ISO-8859-5, a = CP866 (IBM866), m = Mac Cyrillic. Each letter selects a legacy Cyrillic encoding.
convert_cyr_string() expects $str to already be encoded in the $from charset. Passing UTF-8 while claiming KOI8-R source misreads the bytes and garbles the result.