views:

32

answers:

1

Hi,

When counting the length of a utf-8 string in php i use mb-strlen() ,

example:

if (mb_strlen($name, 'UTF-8') < 3) { $error .= 'Name is required. Minimum of 3 characters required'; }

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 sufficent or do i need to use other methods also as i am concerned php may get it wrong for some reason, maybe i am just being sceptical but i don't want people bypassing important validation because php is getting it wrong.

Thanks for any help

+1  A: 

Correct

if (mb_strlen($name, 'UTF-8') < 3) is sufficient enough

make sure header is correct

HTTP-header (Content-Type: text/html; charset=UTF-8)

you can also check alternative for some reason

strlen(utf8_decode($string))

UTF-8 to Code Point Array Converter in PHP

JapanPro
Thanks JapanPro.My HTTP-header is fine thank you.Will check that link out. So i guess mb_strlen() can be trusted then as my http header is as you have said above?Thanks!
PHPLOVER