0

In one script i founded a error from iconv_strlen() function. It try check utf8-len of string in cp1251.

$len = iconv_strlen($cp1252str, "utf-8");

I try use "utf-8//IGNORE" for mute error, but it do not work. Here is example with iconv (//IGNORE work) and iconv_strlen (//IGNORE not work)

<?php
$cp1252str = '';

for ($i = 128; $i < 256; $i++) {
    $cp1252str .= chr($i);
}

iconv("cp1252", "utf-8//IGNORE", $cp1252str);
iconv_strlen($cp1252str, "utf-8//IGNORE");

Output:

PHP Notice: iconv_strlen(): Detected an illegal character in input string in /home/user/tmp/test.php on line 9 PHP Stack trace: PHP 1. {main}() /home/user/tmp/test.php:0 PHP 2. iconv_strlen() /home/user/tmp/test.php:9

How can i mute this error? Only with @?

Anton K.
  • 31
  • 6
  • See that : http://stackoverflow.com/questions/8727735/iconv-detected-an-illegal-character-in-input-string – fito Jan 11 '16 at 10:17
  • What can i see there? Only solutions for iconv(), but i have problem with iconv_strlen(). – Anton K. Jan 11 '16 at 10:52

1 Answers1

0

Get answer on https://bugs.php.net/bug.php?id=71346&edit=2

That's because the charset parameter in iconv_strlen() is for the input string, while the "//IGNORE" flag is only intended to be used in the output charset during conversion, in the iconv() call.

"//IGNORE" means the characters that cannot be represented in the output charset will be discarded. But in your case, you are giving an input string that is invalid UTF-8, and telling iconv_strlen() that it is encoded in the UTF-8 charset, so you are correctly receiving a notice that your input string contains an illegal character.

Anton K.
  • 31
  • 6