The strlen function vs mb_strlen (and others) in PHP

preview_player
Показать описание

Official site

Twitter
Рекомендации по теме
Комментарии
Автор

strlen() used to output wrong count number with non-English characters, now i know the reason. Thank you.

VagoRec
Автор

Thank you for making this video. I had some apps relying on this method...

yismenjorge
Автор

Thanks alex ! Now i'm like "my whole life was a lie" :p

MichaelBelgium
Автор

PHP's serialize uses STRLEN to count strings. I had troubles with C# replicating the serialized array I had because of French strings. I got it to work using the bytes count instead of the actual string's length. ;) So it's not doubtful that something important in your application relies on STRLEN :)

francismori
Автор

the other option at approx 5 min is not good because you utf8_decode the string where it is created, which alters the string in a way which may be undesirable for later use. Better to utf8_decode at the counting step, eg > echo strlen(utf8_decode($string)) < which will count properly but leave the string untouched. But in that case it's prbably easier to use mb_strlen with defining the encoding at the top of the script as it's cleaner if used more than once.

frodev