Reputation: 677
I have a string as: $fullname = 'ワタナベサン';
And some line code for cut a part of string with condition:
if (strlen ( $fullname ) >= 14)
$this->FullName = substr ( $fullname, 0, 10 ) . '...';
else
$this->FullName = $fullname;
But the result appears as wrong string as: 'ワタナ�...'
.
Upvotes: 0
Views: 1616
Reputation: 522042
substr
, and all other core PHP string functions, are not multibyte aware and cannot treat multibyte strings correctly. They only work correctly on ASCII strings or other single-byte encodings. To manipulate multibyte strings correctly, in most cases you need to use the equivalent functions in the MB extension.
See What Every Programmer Absolutely, Positively Needs To Know About Encodings And Character Sets To Work With Text for more information. Welcome to the rabbit hole of character encodings; you have a lot to learn. :o)
Upvotes: 2