PHP: strlen returns character length instead of byte length

I have a wordpress website.

I created a simple page template, for example:

<?php 
 /**
 * Template Name: Test
 */

 echo strlen('');

 ?>

Then I created the page using this template. The page shows the length of the Russian string "Hello" (means "Hello"). I expect to see 12, since the UTF-8 encoded Russian string, consisting of 6 characters, should be 12 bytes in size, but instead I get 6.

I tested the same thing on another server and had the correct value - 12. Therefore, I believe that the reason is the configuration of my server. I have wp 3.2.1 (I had the same problem after upgrading to wp 3.5.1) and PHP 5.3.3.

Currently, I spent about 5 days trying to find a solution, but no luck. Does anyone know what is the reason for this behavior?

+5
4

mbstring.func_overload php.ini. PHP strlen() mb_strlen() ( ).

doc:

, mbstring.func_overload php.ini , , . 1 mail(). 2 , 4 . , 7, , .

, 2 bit , mbstring, ; normal, 0

+7

: http://lt.php.net/manual/en/function.mb-strlen.php?

int mb_strlen ( string $str [, string $encoding ] )
Gets the length of a string.
+1

Do you need to use multibyte string functions for this? For example http://www.php.net/manual/en/function.mb-strlen.php

0
source

For more information on obtaining string length in multibyte characters, see http://php.net/manual/en/function.mb-strlen.php .

0
source

All Articles