In order for PHP to work with Cyrillic strings character by character (including extracting a substring, etc.), you need to use special functions: http://php.net/manual/ru/ref.mbstring.php .
All because of the fact that in Latin 1 character = 1 bit, therefore:
$string = 'XYZ'; echo $string[0]; // будет равно X
But Cyrillic characters occupy 2 bits, therefore:
$string = 'ЭЮЯ'; echo $string[0]; // будет равно
In this case, you can take this into account and work in this way:
$string = 'ЭЮЯ'; echo $string[0] . $string[1]; //output: Э
Or split a line through str_split, specifying split_length = 2:
$string = 'ЭЮЯ'; $arrStr = str_split($string, 2); // = ['Э', 'Ю', 'Я']
But it is better not to do this , because it will now be impossible to work with the Latin alphabet and the rest of the characters:
$string = 'ЭЮЯ. XYZAB'; $strArr = str_split($string, 2); // = ['Э', 'Ю', 'Я', '. ', 'XY', 'ZA', 'B']
By the way, in order to normally divide the term with Russian characters into an array of characters, it is best to do so:
$string = 'ЭЮЯ. XYZAB'; $strArr = preg_split('//u', $string, null, PREG_SPLIT_NO_EMPTY); // = ['Э', 'Ю', 'Я', '.', ' ', 'X', 'Y', 'Z', A', 'B']