tags:

views:

111

answers:

6

mb_strlen only gives number of bytes,not what I wanted.

It should work with multibyte characters.

+6  A: 

mb_strlen maybe ?

Arkh
No,it's wrong...
openid
It's correct, perhaps PHP doesn't recognize your string as Multibyte string? Try something like this: mb_strlen($your_multibyte_string,$encoding) where encoding should be something like "UTF-8" or "UTF-16"
jigfox
How do you use mb_strlen, and what encoding is used for the string you're testing ?
Arkh
A: 

mb_strlen the string being measured for length.

<?php
$str = 'abcdef';
echo strlen($str); // 6

$str = ' ab cd ';
echo strlen($str); // 7
?>

Directly from the documentation.

Russell Dias
A: 

If you are using UTF-8 encoding step thru all bytes in string and count the chars which have the 8th bit NOT set.

This solution does not need the mb extension.

Bernd Ott
+3  A: 

mb_strlen() with mb_internal_encoding('UTF-8')

binaryLV
+6  A: 
mb_strlen($text, "UTF-8");
S.Mark
A: 

I am not sure about mb_strlen, but I use just plain old strlen myself... http://php.net/manual/en/function.strlen.php

RandyMorris