Re: substr and UTF-8
| From: | Michael B Allen | Date: | Wed, 30 Aug 2006 14:08:36 +0000 |
| Subject: | Re: substr and UTF-8 | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-241228@lists.php.net to get a copy of this message | ||
On Wed, 30 Aug 2006 18:34:20 +0700
"Peter Lauri" <lists@dwsasia.com> wrote:
> Hi group,
>
> I want to limit the number of characters that are shown in a script. The
> characters happen to be Thai, and the page is encoded in UTF-8. Everything
> works, except when I want to cut the text (just take start of string).
>
> I do:
>
> echo substr($thaistring, 0, 30);
>
> The beginning of the string works fine, but the last character does mostly
> "break". How can I determine the start and end of a character.
The last byte of a UTF-8 character does not have bit 8 set whereas all
preceeding bytes do.
Mike
--
Michael B Allen
PHP Active Directory SSO
http://www.ioplex.com/