#49146 [Bgs]: strtr cuts char from the end
| From: | felipe@php.net | Date: | Tue, 04 Aug 2009 01:54:34 +0000 |
| Subject: | #49146 [Bgs]: strtr cuts char from the end | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-140627@lists.php.net to get a copy of this message | ||
ID: 49146
Updated by: felipe@php.net
Reported By: juho dot karvilainen at bmf dot wz dot cz
Status: Bogus
Bug Type: Output Control
Operating System: Win XP
PHP Version: 5.2.10
New Comment:
Note this point: "'">'\''
You mistyped the =>, hence you got a 0-key.
Previous Comments:
------------------------------------------------------------------------
[2009-08-04 01:54:24] scottmac@php.net
Your array is also malformed.
array('"'=>'\"',"'">'\'','/'=>'\/')
array(3) {
["""]=>
string(2) "\""
[0]=>
bool(false)
["/"]=>
string(2) "\/"
}
------------------------------------------------------------------------
[2009-08-04 01:38:13] scottmac@php.net
Closing PHP tags always eat the newline after it.
------------------------------------------------------------------------
[2009-08-04 01:36:45] juho dot karvilainen at bmf dot wz dot cz
Description:
------------
looks like the strtr() function (when used with array as 2nd argument)
nibbles a character from the end when it has nothing to replace. (on
UTF-8 page)
Reproduce code:
---------------
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<?php
function safe_js($str){
return
strtr($str,array('"'=>'\"',"'">'\'','/'=>'\/'));
}
?>
line1...<?php echo safe_js(480)?>
line2...
Expected result:
----------------
line1...480
line2
Actual result:
--------------
line1...48line2
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=49146&edit=1