Doc #52024 [NEW]: strtr behaves strangely with multi bytes strings
| From: | francois dot gannaz at silecs dot info | Date: | Tue, 08 Jun 2010 15:29:42 +0000 |
| Subject: | Doc #52024 [NEW]: strtr behaves strangely with multi bytes strings | ||
| Groups: | php.doc.bugs | ||
| Request: | Send a blank email to doc-bugs+get-4518@lists.php.net to get a copy of this message | ||
From:
Operating system: Linux Debian testing amd64
PHP version: 5.3.2
Package: Strings related
Bug Type: Documentation Problem
Bug description:strtr behaves strangely with multi bytes strings
Description:
------------
strtr() only translates _bytes_, not characters.
When translating a multi-byte character to a single byte character, only
the first byte is converted, resulting in a broken string.
The examples given in the doc work with an ISO-8859-1 encoding of the
source file, but not with UTF-8.
IMHO, two solutions;
1) Fix the function. But then the function would need to guess the file
encoding. Hmmm....PHP6?
2) Fix the doc.
The doc title, "strtr â Translate certain characters", is misleading.
Either replace "characters" by "bytes", or add somewhere on the page that
it only works on single-byte encodings. A big warning would be useful.
Test script:
---------------
// in an UTF-8 file
echo strtr("â", "â", "'");
echo strtr("äåö", "äåö", "aao"); // example from
php.net
Expected result:
----------------
'aao
Actual result:
--------------
'��oao�o�
--
Edit bug report at http://bugs.php.net/bug.php?id=52024&edit=1
--
Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=52024&r=trysnapshot52
Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=52024&r=trysnapshot53
Try a snapshot (trunk): http://bugs.php.net/fix.php?id=52024&r=trysnapshottrunk
Fixed in SVN: http://bugs.php.net/fix.php?id=52024&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=52024&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=52024&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=52024&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=52024&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=52024&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=52024&r=support
Expected behavior: http://bugs.php.net/fix.php?id=52024&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=52024&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=52024&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=52024&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=52024&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=52024&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=52024&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=52024&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=52024&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=52024&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=52024&r=mysqlcfg