Bug #71346 [Opn->Nab]: iconv_strlen not work with //IGNORE

From: Date: Fri, 29 Jul 2016 08:19:36 +0000
Subject: Bug #71346 [Opn->Nab]: iconv_strlen not work with //IGNORE
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-202695@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71346&edit=1 ID: 71346 Updated by: cmb@php.net Reported by: anton dot kuzmin dot russia at gmail dot com Summary: iconv_strlen not work with //IGNORE -Status: Open +Status: Not a bug Type: Bug Package: ICONV related Operating System: Ubuntu 14.04 PHP Version: 5.6.17 -Assigned To: +Assigned To: cmb 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. That. Previous Comments: ------------------------------------------------------------------------ [2016-01-21 16:06:58] see dot php at seos dot fr 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. ------------------------------------------------------------------------ [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

« previous php.bugs (#202695) next »