Doc #73750 [Ver->Csd]: Additions to documentation on iconv() //TRANSLIT option
| From: | cmb@php.net | Date: | Sat, 07 Jan 2017 14:50:30 +0000 |
| Subject: | Doc #73750 [Ver->Csd]: Additions to documentation on iconv() //TRANSLIT option | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-14308@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=73750&edit=1
ID: 73750
Updated by: cmb@php.net
Reported by: codedokode at gmail dot com
Summary: Additions to documentation on iconv() //TRANSLIT
option
-Status: Verified
+Status: Closed
Type: Documentation Problem
Package: ICONV related
Operating System: *
PHP Version: Irrelevant
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2017-01-07 14:50:03] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&revision=341618
Log: Fix #73750: Additions to documentation on iconv() //TRANSLIT option
------------------------------------------------------------------------
[2016-12-15 16:43:10] codedokode at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.iconv
---
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:
<?php
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:
---------------
<?php
var_dump(iconv("utf-8", "ASCII//TRANSLIT", "Hello ÐÑивеÑ
Ãö"));
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=73750&edit=1