]> granicus.if.org Git - php/commitdiff
fix strtr() when called with two parameters. this has been broken for some time!
authorThies C. Arntzen <thies@php.net>
Thu, 13 Sep 2001 10:48:41 +0000 (10:48 +0000)
committerThies C. Arntzen <thies@php.net>
Thu, 13 Sep 2001 10:48:41 +0000 (10:48 +0000)
guys, when "optimizing" functions you _shoudl_ write a testcase for the
working function and make _sure_ that it works afterwards!

ext/standard/string.c
ext/standard/tests/strings/strtr.phpt [new file with mode: 0644]

index 75e743832909cc89baafe8f4901bbc143400b102..cf81eead7cec19b50e8fbd9c27b21a307e658fc5 100644 (file)
@@ -1926,7 +1926,7 @@ static void php_strtr_array(zval *return_value, char *str, int slen, HashTable *
        while (zend_hash_get_current_data_ex(hash, (void **)&entry, &hpos) == SUCCESS) {
                switch (zend_hash_get_current_key_ex(hash, &string_key, &string_key_len, &num_key, 0, &hpos)) {
                case HASH_KEY_IS_STRING:
-                       len = string_key_len;
+                       len = string_key_len-1;
                        if (len > maxlen) maxlen = len;
                        if (len < minlen) minlen = len;
                        break; 
diff --git a/ext/standard/tests/strings/strtr.phpt b/ext/standard/tests/strings/strtr.phpt
new file mode 100644 (file)
index 0000000..2cab3a4
--- /dev/null
@@ -0,0 +1,11 @@
+--TEST--
+strtr() function
+--POST--
+--GET--
+--FILE--
+<?php
+$trans = array("hello" => "hi", "hi" => "hello","a" => "A","world" => "planet");
+echo strtr("# hi all, I said hello world! #", $trans) . "\n";
+?>
+--EXPECT--
+# hello All, I sAid hi planet! #