php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71346 iconv_strlen not work with //IGNORE
Submitted: 2016-01-12 07:43 UTC Modified: 2016-07-29 08:19 UTC
From: anton dot kuzmin dot russia at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: ICONV related
PHP Version: 5.6.17 OS: Ubuntu 14.04
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: anton dot kuzmin dot russia at gmail dot com
New email:
PHP Version: OS:

 

 [2016-01-12 07:43 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-01-21 16:06 UTC] 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-07-28 12:44 UTC] cmb@php.net
-Package: mbstring related +Package: ICONV related
 [2016-07-29 08:19 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2016-07-29 08:19 UTC] cmb@php.net
> 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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 18:01:28 2024 UTC