views:

244

answers:

3
<input type="text" id="title" name="title" size="50" maxlength="110" />

You see, the maxlength is 110, but I was shocked when I found that I input 114 characters when I used

echo strlen($title);

Any idea?

By the way, what I input was Japanese text. What's wrong?

+11  A: 

Japanese text is most probably using a multibyte character encoding. Therefore you should make use of mb_strlen().

Best wishes, Fabian

halfdan
+4  A: 

What's wrong?

PHP's string handling, which is based on the assumption that 1 character = 1 byte and leaves it to the programmer to tyke care of encodings everywhere and remember to use the more recent mb_* functions whenever dealing with strings that may use multibyte encodings.

Michael Borgwardt
A: 

maxlength is just a browser lock but it's bypassable in any kind of way including by the unicode encoding. You better provide a server side control for this

TheQult
You make this sound like a hack, which it isn't. This is a bug in PHP's strlen().
Ms2ger
It's an anti-hack.What happen if i open the site and with fiebug i change the maxlenght to 99999999 ?
TheQult