Search code examples
phpiconv

PHP iconv_strlen function display problem


In the code below I'm trying to get the bytes for the character which should be 3 for the first function but I keep getting the value of 1 for each iconv_strlen function below. How can I figure out why this is?

Here is the code:

echo iconv_strlen("こ") . '<br />';
echo iconv_strlen("こ", "UTF-8") . '<br />';

Solution

  • Correct value in first case is 1, not 3.
    If you want to get count of bytes, you can use strlen() function, or change iconv.internal_encoding directive in php.ini or by ini_set() (to ISO-8859-1) - but it will affect all iconv-functions, so I recommend to use strlen().