Re: String Size in Bytes
- From: "J.O. Aho" <user@xxxxxxxxxxx>
- Date: Wed, 30 Aug 2006 20:09:44 +0200
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
.
- Follow-Ups:
- Re: String Size in Bytes
- From: afrinspray
- Re: String Size in Bytes
- References:
- String Size in Bytes
- From: afrinspray
- String Size in Bytes
- Prev by Date: String Size in Bytes
- Next by Date: Attributes problem parsing XML
- Previous by thread: String Size in Bytes
- Next by thread: Re: String Size in Bytes
- Index(es):
Relevant Pages
|