Description

Parameters

The encoding
parameter is the character encoding. If it is omitted, the internal character
encoding value will be used.

Return Values

Returns the number of characters in
stringstr having character encoding
encoding. A multi-byte character is
counted as 1.

Returns FALSE if the given encoding is invalid.

Warning

This function may
return Boolean FALSE, but may also return a non-Boolean value which
evaluates to FALSE. Please read the section on Booleans for more
information. Use the ===
operator for testing the return value of this
function.

If you need length of string in bytes (strlen cannot be trusted anymore because of mbstring.func_overload) you should use <?php mb_strlen($string, '8bit'); ?>.It's the fastest way (still a way slower than strlen, though) to determine byte length of string. Other single byte character sets (ASCII, ISO-8859-1, ...) are several times slower than 8bit.

I have been working with some funny html characters lately and due to the nightmare in manipulating them between mysql and php, I got the database column set to utf8, then store characters with html enity "&#7885;" as ọ in the database and set the encoding on php as "utf8".

This is where mb_strlen became more useful than strlen. While strlen('ọ') gives result as 3, mb_strlen('ọ','UTF-8') gives 1 as expected.

But left(column1,1) in mysql still gives wrong char for a multibyte string. In the example above, I had to do left(column1,3) to get the correct string from mysql. I am now about to investigate multibyte manipulation in mysql.