Reputation: 389
I kinda tried googling everything i could imagine(
I have a russian string stored in a variable And i need to put it on image using gd2 library one character by another. Everything works fine, except putting it 1 by 1. When i try to split it with str_split, or analogs or char by char or substring, i get something like this:
$str = "ку";
$data = str_split($str);
var_dump($data);
array(14) { [0]=> string(1) "&"
[1]=> string(1) "#"
[2]=> string(1) "1"
[3]=> string(1) "0"
[4]=> string(1) "8"
[5]=> string(1) "2"
[6]=> string(1) ";"
[7]=> string(1) "&"
[8]=> string(1) "#"
[9]=> string(1) "1"
[10]=> string(1) "0"
[11]=> string(1) "9"
[12]=> string(1) "1"
[13]=> string(1) ";" }
I tried like everything i could find, but result is still the same. Hope you can help. Thanks.
Upvotes: 0
Views: 355
Reputation: 2120
Your string contains multibyte characters. The basic PHP string functions only work with single-byte characters. There are special mb_*
string functions but the mb_split
function cannot handle your requirements.
So you should use preg_split()
with the unicode flag:
preg_split('//u', "ку", -1, PREG_SPLIT_NO_EMPTY);
Upvotes: 1