strlen() php function giving the wrong length of unicode characters -
this question has answer here:
i trying length of unicode characters string
$text = 'نام سلطان م'; $length = strlen($text); echo $length;
output
20
how determines length of unicode characters string?
strlen()
not handling multibyte characters correctly, assumes 1 char equals 1 byte, invalud unicode. behavior documented here: http://php.net/strlen
strlen() returns number of bytes rather number of characters in string.
solution use mb_strlen()
function instead (mb
stands multi byte
) (see mb_strlen() docs).
edit
if reason chanage in code not possible/doable, 1 may want ensure string functions automatically overloaded multibyte counterparts. supported php , documented here.
please note may want edit php.ini
ensure mb_string works want to. available settings documented here.
Comments
Post a Comment