When counting the length of an UTF-8 string in PHP I use mb_strlen()
.
For example:
if (mb_strlen($name, 'UTF-8') < 3) {
$error .= 'Name is required. Minimum of 3 characters required in name.';
}
As the text fields can accept any language (multilanguage), I want to make sure that PHP will count mutltilanguage UTF-8 characters correctly.
Is this sufficient or do I need to use other methods? I am concerned PHP may get it wrong for some reason, or maybe I am just being skeptical, but I don't want people bypassing important validation because PHP is getting it wrong.