|
Posted by J.O. Aho on 08/30/06 18:09
afrinspray wrote:
> How can I calculate the length of a string in bytes when the string can
> contain any characters that are legal in HTML? Will this work (from
> php.net):
> $length = strlen(utf8_decode($s))
This would give a smaller size than what it is, as characters like 'ö' or 'ø'
would be one byte and not two bytes as they would be in utf8.
$length = mb_strlen($utf8_string, 'latin1');
this is a dirty trick to make the byte length instead of the string length,
you read the utf string as iso, which makes the multibyte characters to
counted as 2+ bytes instead of being one character (one byte).
> I'm guess I'm just confused about multi-byte characters vs. single byte
> ones. Thanks in advance.
yeah, characters with ASCII values below 128 are one byte, while everyone one
else is two or more bytes.
//Aho
Navigation:
[Reply to this message]
|