Re: String Size in Bytes



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
.



Relevant Pages

  • Re: detect language
    ... Peter wrote: ... how can i detect what language it is? ... An UTF string can have characters of more than one languages. ...
    (comp.lang.php)
  • Re: String Size in Bytes
    ... would be one byte and not two bytes as they would be in utf8. ... 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 ... yeah, characters with ASCII values below 128 are one byte, while everyone one ...
    (alt.php)
  • Re: can I know how to write a html parser in C
    ... Are the lines truly limited to 80 characters of text? ... null-terminated character string size of 249 characters. ... Note too that in the general case it is perfectly acceptable in HTML ... much a beginner at C (and possibly a beginner at programming ...
    (comp.lang.c)
  • Re: Subject text length limit in system.net.mail?
    ... Finally figured what it was - Internet Message Filter for Exchange settings ... decided to change the mail server? ... to pre-generated html pages published somewhere. ... AM> stuff for invalid characters that might cause the process to ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: [PHP] generating an html intro text ...
    ... You would have to search out and pull in all closing tags. ... grab 256 characters -- The string. ... html markup should not go towards the string length count, ...
    (php.general)