If HTML maxlength is 110, why can I input 114 characters?
<input type="text" id="title" name="title" size="50" ma开发者_JAVA百科xlength="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?
Japanese text is most probably using a multibyte character encoding. Therefore you should make use of mb_strlen().
Best wishes, Fabian
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.
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
精彩评论