Doc #52024 [Opn->Csd]: strtr behaves strangely with multi bytes strings

From: Date: Sat, 23 Oct 2010 00:12:19 +0000
Subject: Doc #52024 [Opn->Csd]: strtr behaves strangely with multi bytes strings
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-5339@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=52024&edit=1 ID: 52024 Updated by: cataphract@php.net Reported by: francois dot gannaz at silecs dot info Summary: strtr behaves strangely with multi bytes strings -Status: Open +Status: Closed Type: Documentation Problem Package: Documentation problem Operating System: Linux Debian testing amd64 PHP Version: 5.3.2 -Assigned To: +Assigned To: cataphract Block user comment: N New Comment: I've already improved the documentation of strtr for bug #52967. Basically, strtr() has two different algorithms implemented under the same name, in one case it translates bytes, in the other one it replaces strings. Previous Comments: ------------------------------------------------------------------------ [2010-06-08 17:29:42] francois dot gannaz at silecs dot info 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 this bug report at http://bugs.php.net/bug.php?id=52024&edit=1

« previous php.doc.bugs (#5339) next »