You are here: Re: String Size in Bytes « All PHP « IT news, forums, messages
Re: String Size in Bytes

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация