Doc #73750 [NEW]: Additions to documentation on iconv() //TRANSLIT option
| From: | codedokode at gmail dot com | Date: | Thu, 15 Dec 2016 16:43:12 +0000 |
| Subject: | Doc #73750 [NEW]: Additions to documentation on iconv() //TRANSLIT option | ||
| Groups: | php.doc.bugs | ||
| Request: | Send a blank email to doc-bugs+get-14241@lists.php.net to get a copy of this message | ||
From: codedokode at gmail dot com
Operating system: Windows
PHP version: Irrelevant
Package: Documentation problem
Bug Type: Documentation Problem
Bug description:Additions to documentation on iconv() //TRANSLIT option
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 bug report at https://bugs.php.net/bug.php?id=73750&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=73750&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=73750&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=73750&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=73750&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=73750&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=73750&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=73750&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=73750&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=73750&r=support
Expected behavior: https://bugs.php.net/fix.php?id=73750&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=73750&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=73750&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=73750&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=73750&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=73750&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=73750&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=73750&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=73750&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=73750&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=73750&r=mysqlcfg