Question

<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?

Was it helpful?

Solution

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

Best wishes, Fabian

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top