|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #73750 Additions to documentation on iconv() //TRANSLIT option
Submitted: 2016-12-15 16:43 UTC Modified: 2017-01-07 14:50 UTC
From: codedokode at gmail dot com Assigned: cmb (profile)
Status: Closed Package: ICONV related
PHP Version: Irrelevant OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: codedokode at gmail dot com
New email:
PHP Version: OS:


 [2016-12-15 16:43 UTC] codedokode at gmail dot com
From manual page:

The documentation on iconv() mentions //TRANSLIT option that transliterates the characters. But this option does not always work, it depends on what library is providing iconv() function. I think we should add a note about it so that the users would not have to look through PHP sources, build configurations and external libraries documentation to find out why their code does not work as expected.  

For example this code behaves differently on different OS: 

var_dump(iconv("utf-8", "ASCII//TRANSLIT", "Hello Привет ßö"));

On Linux it prints "Hello ?????? sso" (cyrillic characters are transliterated into question marks). On Windows iconv() returns false and a notice is generated ("PHP Notice:  iconv(): Detected an illegal character in input string").

That is because PHP uses glibc version of iconv() on Linux and something else (libiconv, I guess) on Windows. This is difficult to find out unless the developer knows C and has a patience to understand how PHP iconv() function is implemented. I understand that PHP provides just a wrapper around external function but now the documentation asserts that //TRANSLIT option works.

I suggest adding the following notice to documentation: 

//TRANSLIT option currently only works in Linux versions of PHP built with iconv()  function impoted from glibc (<how to find out what library is used>). On Windows this option usually doesn't work and iconv() will generate notice and return false if the character cannot be represented in the output charset. The developers of portable programs are recommended not to use it.

//TRANSLIT option does not transliterates characters from non-latin alphabets into latin characters even if they look or sound the same. For example, when converting from utf-8 to ASCII//TRANSLIT it will convert non-latin letters to question marks, not latin characters.

Test script:
var_dump(iconv("utf-8", "ASCII//TRANSLIT", "Hello Привет ßö"));


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-12-31 18:41 UTC]
-Assigned To: +Assigned To: cmb
 [2017-01-07 14:48 UTC]
-Status: Assigned +Status: Verified -Package: Documentation problem +Package: ICONV related -Operating System: Windows +Operating System: *
 [2017-01-07 14:50 UTC]
Automatic comment from SVN on behalf of cmb
Log: Fix #73750: Additions to documentation on iconv() //TRANSLIT option
 [2017-01-07 14:50 UTC]
-Status: Verified +Status: Closed
 [2017-01-07 14:50 UTC]
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.
 [2020-02-07 06:06 UTC]
Automatic comment on behalf of cmb
Log: Fix #73750: Additions to documentation on iconv() //TRANSLIT option
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu May 13 22:01:24 2021 UTC