Bug #71346 [Com]: iconv_strlen not work with //IGNORE
Edit report at https://bugs.php.net/bug.php?id=71346&edit=1
ID: 71346
Comment by: see dot php at seos dot fr
Reported by: anton dot kuzmin dot russia at gmail dot com
Summary: iconv_strlen not work with //IGNORE
Status: Open
Type: Bug
Package: mbstring related
Operating System: Ubuntu 14.04
PHP Version: 5.6.17
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2016-01-12 07:43:03] anton dot kuzmin dot russia at gmail dot com
Description:
------------
Hello. If try get length of cp1251-string with iconv_strlen() and encoding utf-8, this function
print error "PHP Notice: iconv_strlen(): Detected an illegal character". If i add to
encoding (utf-8) "//IGNORE" - notice print too.
In iconv() this work and notice not show, but in iconv_strlen() is not work.
Test script:
---------------
<?php
$cp1252str = '';
for ($i = 128; $i < 256; $i++) {
$cp1252str .= chr($i);
}
print "Work iconv:\n";
iconv("cp1252", "utf-8//IGNORE", $cp1252str);
print "Work iconv_strlen:\n";
iconv_strlen($cp1252str, "utf-8//IGNORE");
Expected result:
----------------
Notice not show
Actual result:
--------------
Notice show
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71346&edit=1
Thread (3 messages)