php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26426 strtr translate numbers with "Array" when using replace_pairs
Submitted: 2003-11-26 10:30 UTC Modified: 2003-11-26 10:32 UTC
From: elias dot norstrom at lunchinfo dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.3.3 OS: Linux Debian 2.4.21
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: elias dot norstrom at lunchinfo dot com
New email:
PHP Version: OS:

 

 [2003-11-26 10:30 UTC] elias dot norstrom at lunchinfo dot com
Description:
------------
Trying to translate swedish encoded characters with strtr function using replace_pairs.

The function translate numbers from 0 to sizeof(replace_pairs-array) to the string "Array".

See example to reproduce.

Reproduce code:
---------------
<?php
$strSearchWord = "abc123&aring;poli987654321";

$arrTransformChars[] = array('&Aring;' => '?');
$arrTransformChars[] = array('&Auml;'  => '?');
$arrTransformChars[] = array('&Ouml;'  => '?');
$arrTransformChars[] = array('&aring;' => '?');
$arrTransformChars[] = array('&auml;'  => '?');
$arrTransformChars[] = array('&ouml;'  => '?');


echo $strSearchWord . "<br>";
$strSearchWord = strtr($strSearchWord,$arrTransformChars);
echo $strSearchWord . "<br>";
exit;
?>

Expected result:
----------------
abc123&aring;poli987654321
abc123?poli987654321

Actual result:
--------------
abc123?poli987654321
abcArrayArrayArray?poli9876ArrayArrayArrayArrayArray

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-11-26 10:32 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

You\'re filling the array wrongly:

$arrTransformChars[\'&Aring\'] = \'....

you\'re creating a 2d array, which is not what this function wants.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 16 19:01:32 2025 UTC