]> granicus.if.org Git - php/commitdiff
New version of addcslashes.phpt, implode1.phpt, strpos.phpt, str_replace.phpt, substr...
authorRaghubansh Kumar <kraghuba@php.net>
Sat, 12 May 2007 12:12:26 +0000 (12:12 +0000)
committerRaghubansh Kumar <kraghuba@php.net>
Sat, 12 May 2007 12:12:26 +0000 (12:12 +0000)
ext/standard/tests/strings/addcslashes.phpt [new file with mode: 0644]
ext/standard/tests/strings/chr_ord.phpt
ext/standard/tests/strings/implode1.phpt
ext/standard/tests/strings/md5_file.phpt [new file with mode: 0644]
ext/standard/tests/strings/str_repeat.phpt
ext/standard/tests/strings/str_replace.phpt
ext/standard/tests/strings/strpos.phpt
ext/standard/tests/strings/strstr.phpt
ext/standard/tests/strings/substr.phpt [new file with mode: 0644]
ext/standard/tests/strings/substr_count.phpt
ext/standard/tests/strings/trim1.phpt [new file with mode: 0644]

diff --git a/ext/standard/tests/strings/addcslashes.phpt b/ext/standard/tests/strings/addcslashes.phpt
new file mode 100644 (file)
index 0000000..856d2e6
Binary files /dev/null and b/ext/standard/tests/strings/addcslashes.phpt differ
index 56cfef70a34160e6a6f0a8d59210a48ac16fc317..8c91b4cba07af3092aa78cb29d8424655e632fe8 100644 (file)
Binary files a/ext/standard/tests/strings/chr_ord.phpt and b/ext/standard/tests/strings/chr_ord.phpt differ
index 1aff3d81c99814820dcaac21f8901ad049e3ccde..c99365339c9f67ac35cf84ce9138f8f589f81f0f 100644 (file)
Binary files a/ext/standard/tests/strings/implode1.phpt and b/ext/standard/tests/strings/implode1.phpt differ
diff --git a/ext/standard/tests/strings/md5_file.phpt b/ext/standard/tests/strings/md5_file.phpt
new file mode 100644 (file)
index 0000000..a7c3e10
Binary files /dev/null and b/ext/standard/tests/strings/md5_file.phpt differ
index f91bd31b670be9d9b9a7cfeee10f3a5acf7748de..c8995d10dd8200150ac2338ad4d8fbb1e516c81d 100644 (file)
Binary files a/ext/standard/tests/strings/str_repeat.phpt and b/ext/standard/tests/strings/str_repeat.phpt differ
index f8967d916576865abf5786b2fcf82b95c088418d..5105e5ada2f2345873ad05e9ee5fde0257b0b957 100644 (file)
 --TEST--
-str_replace() tests
+Test str_replace() function
 --FILE--
 <?php
+/* 
+  Prototype: mixed str_replace(mixed $search, mixed $replace, 
+                               mixed $subject [, int &$count]);
+  Description: Replace all occurrences of the search string with 
+               the replacement string
+*/
 
-var_dump(str_replace("", "", ""));
+echo "\n*** Testing str_replace() on basic operations ***\n";
 
-var_dump(str_replace("e", "b", "test"));
+var_dump( str_replace("", "", "") );
 
-var_dump(str_replace("", "", "", $count));
-var_dump($count);
+var_dump( str_replace("e", "b", "test") );
 
-var_dump(str_replace("q", "q", "q", $count));
-var_dump($count);
+var_dump( str_replace("", "", "", $count) );
+var_dump( $count );
 
-var_dump(str_replace("long string here", "", "", $count));
-var_dump($count);
+var_dump( str_replace("q", "q", "q", $count) );
+var_dump( $count );
 
-var_dump(str_replace(chr(0), "a", "", $count));
-var_dump($count);
+var_dump( str_replace("long string here", "", "", $count) );
+var_dump( $count );
 
-var_dump(str_replace(chr(0), "a", chr(0), $count));
-var_dump($count);
+$fp = fopen( __FILE__, "r" );
+var_dump( str_replace($fp, $fp, $fp, $fp) );
+var_dump( $fp );
+
+echo "\n*** Testing str_replace() with various search values ***";
+$search_arr = array( TRUE, FALSE, 1, 0, -1, "1", "0", "-1",  NULL, 
+                     array(), "php", "");
+
+$i = 0;
+/* loop through to replace the matched elements in the array */
+foreach( $search_arr as $value ) {
+  echo "\n-- Iteration $i --\n";
+  /* replace the string in array */
+  var_dump( str_replace($value, "FOUND", $search_arr, $count) ); 
+  var_dump( $count );
+  $i++;
+}
+
+echo "\n*** Testing str_replace() with various subjects ***";
+$subject = "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE\000
+           \x000\xABCD\0abcd \xXYZ\tabcd $$@#%^&*!~,.:;?: !!Hello, World 
+           ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)";
+
+/* needles in an array to be compared in the string $string */
+$search_str = array ( 
+  "Hello, World",
+  'Hello, World',
+  '!!Hello, World',
+  "??Hello, World",
+  "$@#%^&*!~,.:;?",
+  "123",
+  123,
+  "-1.2345",
+  -1.2344,
+  "abcd",
+  'XYZ',
+  NULL,
+  "NULL",
+  "0",
+  0,
+  "",
+  " ",
+  "\0",
+  "\x000",
+  "\xABC",
+  "\0000",
+  ".3",
+  TRUE,
+  "TRUE",
+  "1",
+  1,
+  FALSE,
+  "FALSE",
+  " ",
+  "          ",
+  'b',
+  '\t',
+  "\t",
+  chr(128).chr(234).chr(65).chr(255).chr(256),
+  $subject
+);
+
+/* loop through to get the  $string */
+for( $i = 0; $i < count($search_str); $i++ ) {
+  echo "\n--- Iteration $i ---";
+  echo "\n-- String after replacing the search value is => --\n";
+  var_dump( str_replace($search_str[$i], "FOUND", $subject, $count) );
+  echo "-- search string has found '$count' times\n";
+}
+  
 
-var_dump(str_replace("multi", "a", "aaa", $count));
+echo "\n*** Testing Miscelleneous input data ***\n";
+/*  If replace has fewer values than search, then an empty 
+    string is used for the rest of replacement values */
+var_dump( str_replace(array("a", "a", "b"), 
+                     array("q", "q"), 
+                     "aaabb", $count
+                    )
+       );
+var_dump($count);
+var_dump( str_replace(array("a", "a", "b"), 
+                      array("q", "q"), 
+                      array("aaa", "bbb", "ccc"), 
+                      $count
+                     )
+        );
 var_dump($count);
 
-var_dump(str_replace("a", "multi", "aaa", $count));
+
+echo "\n-- Testing objects --\n";
+/* we get "Catchable fatal error: saying Object of class could not be converted
+        to string" by default, when an object is passed instead of string:
+The error can be  avoided by chosing the __toString magix method as follows: */
+
+class subject 
+{
+  function __toString() {
+    return "Hello, world";
+  }
+}
+$obj_subject = new subject;
+
+class search 
+{
+  function __toString() {
+    return "Hello, world";
+  }
+}
+$obj_search = new search;
+
+class replace 
+{
+  function __toString() {
+    return "Hello, world";
+  }
+}
+$obj_replace = new replace;
+
+var_dump(str_replace("$obj_search", "$obj_replace", "$obj_subject", $count));
 var_dump($count);
 
+
+echo "\n-- Testing arrays --\n";
 var_dump(str_replace(array("a", "a", "b"), "multi", "aaa", $count));
 var_dump($count);
 
-var_dump(str_replace(array("a", "a", "b"), array("q", "q", "c"), "aaa", $count));
+var_dump(str_replace( array("a", "a", "b"),
+                      array("q", "q", "c"), 
+                      "aaa", $count
+                    )
+);
 var_dump($count);
 
-var_dump(str_replace(array("a", "a", "b"), array("q", "q", "c"), array("aaa", "bbb"), $count));
+var_dump(str_replace( array("a", "a", "b"),
+                      array("q", "q", "c"), 
+                      array("aaa", "bbb"), 
+                      $count
+                    )
+);
 var_dump($count);
 
 var_dump(str_replace("a", array("q", "q", "c"), array("aaa", "bbb"), $count));
@@ -46,13 +174,70 @@ var_dump($count);
 var_dump(str_replace(1, 3, array("aaa1", "2bbb"), $count));
 var_dump($count);
 
-$fp = fopen(__FILE__, "r");
-var_dump(str_replace($fp, $fp, $fp, $fp));
-var_dump($fp);
+
+echo "\n-- Testing Resources --\n";
+$resource1 = fopen( __FILE__, "r" );
+$resource2 = opendir( "." );
+var_dump(str_replace("stream", "FOUND", $resource1, $count)); 
+var_dump($count);
+var_dump(str_replace("stream", "FOUND", $resource2, $count));
+var_dump($count);
+
+
+echo "\n-- Testing a longer and heredoc string --\n";
+$string = <<<EOD
+abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
+abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
+abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
+abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
+abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
+abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
+abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
+@#$%^&**&^%$#@!~:())))((((&&&**%$###@@@!!!~~~~@###$%^&*
+abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
+EOD;
+
+var_dump( str_replace("abcdef", "FOUND", $string, $count) );
+var_dump( $count );
+
+echo "\n-- Testing a heredoc null string --\n";
+$str = <<<EOD
+EOD;
+var_dump( str_replace("", "FOUND", $str, $count) );
+var_dump( $count );
+
+
+echo "\n-- Testing simple and complex syntax strings --\n";
+$str = 'world';
+
+/* Simple syntax */
+var_dump( str_replace("world", "FOUND", "$str") );
+var_dump( str_replace("world'S", "FOUND", "$str'S") );
+var_dump( str_replace("worldS", "FOUND", "$strS") );
+
+/* String with curly braces, complex syntax */
+var_dump( str_replace("worldS", "FOUND", "${str}S") );
+var_dump( str_replace("worldS", "FOUND", "{$str}S") );
+
+
+echo "\n*** Testing error conditions ***";
+/* Invalid arguments */
+var_dump( str_replace() );
+var_dump( str_replace("") );
+var_dump( str_replace(NULL) );
+var_dump( str_replace(1, 2) );
+var_dump( str_replace(1,2,3,$var,5) );
 
 echo "Done\n";
+
+--CLEAN--
+fclose($fp);
+fclose($resource1);
+closedir($resource2);
+
 ?>
 --EXPECTF--    
+*** Testing str_replace() on basic operations ***
 string(0) ""
 string(4) "tbst"
 string(0) ""
@@ -61,102 +246,711 @@ string(1) "q"
 int(1)
 string(0) ""
 int(0)
-string(0) ""
-int(0)
-string(1) "a"
+string(14) "Resource id #5"
 int(1)
-string(3) "aaa"
+
+*** Testing str_replace() with various search values ***
+-- Iteration 0 --
+array(12) {
+  [0]=>
+  string(5) "FOUND"
+  [1]=>
+  string(0) ""
+  [2]=>
+  string(5) "FOUND"
+  [3]=>
+  string(1) "0"
+  [4]=>
+  string(6) "-FOUND"
+  [5]=>
+  string(5) "FOUND"
+  [6]=>
+  string(1) "0"
+  [7]=>
+  string(6) "-FOUND"
+  [8]=>
+  string(0) ""
+  [9]=>
+  array(0) {
+  }
+  [10]=>
+  string(3) "php"
+  [11]=>
+  string(0) ""
+}
+int(5)
+
+-- Iteration 1 --
+array(12) {
+  [0]=>
+  string(1) "1"
+  [1]=>
+  string(0) ""
+  [2]=>
+  string(1) "1"
+  [3]=>
+  string(1) "0"
+  [4]=>
+  string(2) "-1"
+  [5]=>
+  string(1) "1"
+  [6]=>
+  string(1) "0"
+  [7]=>
+  string(2) "-1"
+  [8]=>
+  string(0) ""
+  [9]=>
+  array(0) {
+  }
+  [10]=>
+  string(3) "php"
+  [11]=>
+  string(0) ""
+}
 int(0)
-string(15) "multimultimulti"
-int(3)
-string(15) "multimultimulti"
-int(3)
-string(3) "qqq"
-int(3)
-array(2) {
+
+-- Iteration 2 --
+array(12) {
   [0]=>
-  string(3) "qqq"
+  string(5) "FOUND"
   [1]=>
-  string(3) "ccc"
+  string(0) ""
+  [2]=>
+  string(5) "FOUND"
+  [3]=>
+  string(1) "0"
+  [4]=>
+  string(6) "-FOUND"
+  [5]=>
+  string(5) "FOUND"
+  [6]=>
+  string(1) "0"
+  [7]=>
+  string(6) "-FOUND"
+  [8]=>
+  string(0) ""
+  [9]=>
+  array(0) {
+  }
+  [10]=>
+  string(3) "php"
+  [11]=>
+  string(0) ""
 }
-int(6)
+int(5)
 
-Notice: Array to string conversion in %s on line %d
-array(2) {
+-- Iteration 3 --
+array(12) {
   [0]=>
-  string(15) "ArrayArrayArray"
+  string(1) "1"
   [1]=>
-  string(3) "bbb"
+  string(0) ""
+  [2]=>
+  string(1) "1"
+  [3]=>
+  string(5) "FOUND"
+  [4]=>
+  string(2) "-1"
+  [5]=>
+  string(1) "1"
+  [6]=>
+  string(5) "FOUND"
+  [7]=>
+  string(2) "-1"
+  [8]=>
+  string(0) ""
+  [9]=>
+  array(0) {
+  }
+  [10]=>
+  string(3) "php"
+  [11]=>
+  string(0) ""
 }
-int(3)
-array(2) {
+int(2)
+
+-- Iteration 4 --
+array(12) {
   [0]=>
-  string(3) "111"
+  string(1) "1"
   [1]=>
-  string(3) "bbb"
+  string(0) ""
+  [2]=>
+  string(1) "1"
+  [3]=>
+  string(1) "0"
+  [4]=>
+  string(5) "FOUND"
+  [5]=>
+  string(1) "1"
+  [6]=>
+  string(1) "0"
+  [7]=>
+  string(5) "FOUND"
+  [8]=>
+  string(0) ""
+  [9]=>
+  array(0) {
+  }
+  [10]=>
+  string(3) "php"
+  [11]=>
+  string(0) ""
 }
-int(3)
-array(2) {
+int(2)
+
+-- Iteration 5 --
+array(12) {
   [0]=>
-  string(4) "aaa3"
+  string(5) "FOUND"
   [1]=>
-  string(4) "2bbb"
+  string(0) ""
+  [2]=>
+  string(5) "FOUND"
+  [3]=>
+  string(1) "0"
+  [4]=>
+  string(6) "-FOUND"
+  [5]=>
+  string(5) "FOUND"
+  [6]=>
+  string(1) "0"
+  [7]=>
+  string(6) "-FOUND"
+  [8]=>
+  string(0) ""
+  [9]=>
+  array(0) {
+  }
+  [10]=>
+  string(3) "php"
+  [11]=>
+  string(0) ""
+}
+int(5)
+
+-- Iteration 6 --
+array(12) {
+  [0]=>
+  string(1) "1"
+  [1]=>
+  string(0) ""
+  [2]=>
+  string(1) "1"
+  [3]=>
+  string(5) "FOUND"
+  [4]=>
+  string(2) "-1"
+  [5]=>
+  string(1) "1"
+  [6]=>
+  string(5) "FOUND"
+  [7]=>
+  string(2) "-1"
+  [8]=>
+  string(0) ""
+  [9]=>
+  array(0) {
+  }
+  [10]=>
+  string(3) "php"
+  [11]=>
+  string(0) ""
+}
+int(2)
+
+-- Iteration 7 --
+array(12) {
+  [0]=>
+  string(1) "1"
+  [1]=>
+  string(0) ""
+  [2]=>
+  string(1) "1"
+  [3]=>
+  string(1) "0"
+  [4]=>
+  string(5) "FOUND"
+  [5]=>
+  string(1) "1"
+  [6]=>
+  string(1) "0"
+  [7]=>
+  string(5) "FOUND"
+  [8]=>
+  string(0) ""
+  [9]=>
+  array(0) {
+  }
+  [10]=>
+  string(3) "php"
+  [11]=>
+  string(0) ""
+}
+int(2)
+
+-- Iteration 8 --
+array(12) {
+  [0]=>
+  string(1) "1"
+  [1]=>
+  string(0) ""
+  [2]=>
+  string(1) "1"
+  [3]=>
+  string(1) "0"
+  [4]=>
+  string(2) "-1"
+  [5]=>
+  string(1) "1"
+  [6]=>
+  string(1) "0"
+  [7]=>
+  string(2) "-1"
+  [8]=>
+  string(0) ""
+  [9]=>
+  array(0) {
+  }
+  [10]=>
+  string(3) "php"
+  [11]=>
+  string(0) ""
 }
-int(1)
-string(%d) "Resource id #%d"
-int(1)
-Done
---UEXPECTF--
-unicode(0) ""
-unicode(4) "tbst"
-unicode(0) ""
-int(0)
-unicode(1) "q"
-int(1)
-unicode(0) ""
 int(0)
-unicode(0) ""
+
+-- Iteration 9 --
+array(12) {
+  [0]=>
+  string(1) "1"
+  [1]=>
+  string(0) ""
+  [2]=>
+  string(1) "1"
+  [3]=>
+  string(1) "0"
+  [4]=>
+  string(2) "-1"
+  [5]=>
+  string(1) "1"
+  [6]=>
+  string(1) "0"
+  [7]=>
+  string(2) "-1"
+  [8]=>
+  string(0) ""
+  [9]=>
+  array(0) {
+  }
+  [10]=>
+  string(3) "php"
+  [11]=>
+  string(0) ""
+}
 int(0)
-unicode(1) "a"
+
+-- Iteration 10 --
+array(12) {
+  [0]=>
+  string(1) "1"
+  [1]=>
+  string(0) ""
+  [2]=>
+  string(1) "1"
+  [3]=>
+  string(1) "0"
+  [4]=>
+  string(2) "-1"
+  [5]=>
+  string(1) "1"
+  [6]=>
+  string(1) "0"
+  [7]=>
+  string(2) "-1"
+  [8]=>
+  string(0) ""
+  [9]=>
+  array(0) {
+  }
+  [10]=>
+  string(5) "FOUND"
+  [11]=>
+  string(0) ""
+}
 int(1)
-unicode(3) "aaa"
+
+-- Iteration 11 --
+array(12) {
+  [0]=>
+  string(1) "1"
+  [1]=>
+  string(0) ""
+  [2]=>
+  string(1) "1"
+  [3]=>
+  string(1) "0"
+  [4]=>
+  string(2) "-1"
+  [5]=>
+  string(1) "1"
+  [6]=>
+  string(1) "0"
+  [7]=>
+  string(2) "-1"
+  [8]=>
+  string(0) ""
+  [9]=>
+  array(0) {
+  }
+  [10]=>
+  string(3) "php"
+  [11]=>
+  string(0) ""
+}
 int(0)
-unicode(15) "multimultimulti"
-int(3)
-unicode(15) "multimultimulti"
+
+*** Testing str_replace() with various subjects ***
+--- Iteration 0 ---
+-- String after replacing the search value is => --
+string(177) "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE\0
+           \00«CD\0abcd \xXYZ    abcd $$@#%^&*!~,.:;?: !!FOUND 
+           ?FOUND chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
+-- search string has found '2' times
+
+--- Iteration 1 ---
+-- String after replacing the search value is => --
+string(177) "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE\0
+           \00«CD\0abcd \xXYZ    abcd $$@#%^&*!~,.:;?: !!FOUND 
+           ?FOUND chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
+-- search string has found '2' times
+
+--- Iteration 2 ---
+-- String after replacing the search value is => --
+string(182) "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE\0
+           \00«CD\0abcd \xXYZ    abcd $$@#%^&*!~,.:;?: FOUND 
+           ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
+-- search string has found '1' times
+
+--- Iteration 3 ---
+-- String after replacing the search value is => --
+string(191) "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE\0
+           \00«CD\0abcd \xXYZ    abcd $$@#%^&*!~,.:;?: !!Hello, World 
+           ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
+-- search string has found '0' times
+
+--- Iteration 4 ---
+-- String after replacing the search value is => --
+string(182) "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE\0
+           \00«CD\0abcd \xXYZ    abcd $FOUND: !!Hello, World 
+           ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
+-- search string has found '1' times
+
+--- Iteration 5 ---
+-- String after replacing the search value is => --
+string(191) "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE\0
+           \00«CD\0abcd \xXYZ    abcd $$@#%^&*!~,.:;?: !!Hello, World 
+           ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
+-- search string has found '0' times
+
+--- Iteration 6 ---
+-- String after replacing the search value is => --
+string(191) "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE\0
+           \00«CD\0abcd \xXYZ    abcd $$@#%^&*!~,.:;?: !!Hello, World 
+           ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
+-- search string has found '0' times
+
+--- Iteration 7 ---
+-- String after replacing the search value is => --
+string(189) "Hello, world,0120333.3445FOUND67          NULL TRUE FALSE\0
+           \00«CD\0abcd \xXYZ    abcd $$@#%^&*!~,.:;?: !!Hello, World 
+           ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
+-- search string has found '1' times
+
+--- Iteration 8 ---
+-- String after replacing the search value is => --
+string(191) "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE\0
+           \00«CD\0abcd \xXYZ    abcd $$@#%^&*!~,.:;?: !!Hello, World 
+           ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
+-- search string has found '0' times
+
+--- Iteration 9 ---
+-- String after replacing the search value is => --
+string(193) "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE\0
+           \00«CD\0FOUND \xXYZ   FOUND $$@#%^&*!~,.:;?: !!Hello, World 
+           ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
+-- search string has found '2' times
+
+--- Iteration 10 ---
+-- String after replacing the search value is => --
+string(193) "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE\0
+           \00«CD\0abcd \xFOUND  abcd $$@#%^&*!~,.:;?: !!Hello, World 
+           ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
+-- search string has found '1' times
+
+--- Iteration 11 ---
+-- String after replacing the search value is => --
+string(191) "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE\0
+           \00«CD\0abcd \xXYZ    abcd $$@#%^&*!~,.:;?: !!Hello, World 
+           ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
+-- search string has found '0' times
+
+--- Iteration 12 ---
+-- String after replacing the search value is => --
+string(192) "Hello, world,0120333.3445-1.234567          FOUND TRUE FALSE\0
+           \00«CD\0abcd \xXYZ    abcd $$@#%^&*!~,.:;?: !!Hello, World 
+           ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
+-- search string has found '1' times
+
+--- Iteration 13 ---
+-- String after replacing the search value is => --
+string(207) "Hello, world,FOUND12FOUND333.3445-1.234567          NULL TRUE FALSE\0
+           \0FOUND«CD\0abcd \xXYZ        abcd $$@#%^&*!~,.:;?: !!Hello, World 
+           ?Hello, World chr(FOUND).chr(128).chr(234).chr(65).chr(255).chr(256)"
+-- search string has found '4' times
+
+--- Iteration 14 ---
+-- String after replacing the search value is => --
+string(207) "Hello, world,FOUND12FOUND333.3445-1.234567          NULL TRUE FALSE\0
+           \0FOUND«CD\0abcd \xXYZ        abcd $$@#%^&*!~,.:;?: !!Hello, World 
+           ?Hello, World chr(FOUND).chr(128).chr(234).chr(65).chr(255).chr(256)"
+-- search string has found '4' times
+
+--- Iteration 15 ---
+-- String after replacing the search value is => --
+string(191) "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE\0
+           \00«CD\0abcd \xXYZ    abcd $$@#%^&*!~,.:;?: !!Hello, World 
+           ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
+-- search string has found '0' times
+
+--- Iteration 16 ---
+-- String after replacing the search value is => --
+string(307) "Hello,FOUNDworld,0120333.3445-1.234567FOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUNDNULLFOUNDTRUEFOUNDFALSE\0
+FOUND  FOUNDFOUNDFOUNDFOUND\00«CD\0abcdFOUND\xXYZ        abcdFOUND$$@#%^&*!~,.:;?:FOUND!!Hello,FOUNDWorldFOUND
+       FOUNDFOUNDFOUNDFOUND?Hello,FOUNDWorldFOUNDchr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
+-- search string has found '29' times
+
+--- Iteration 17 ---
+-- String after replacing the search value is => --
+string(203) "Hello, world,0120333.3445-1.234567          NULL TRUE FALSEFOUND
+           FOUND0«CDFOUNDabcd \xXYZ    abcd $$@#%^&*!~,.:;?: !!Hello, World 
+           ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
+-- search string has found '3' times
+
+--- Iteration 18 ---
+-- String after replacing the search value is => --
+string(194) "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE\0
+           FOUND«CD\0abcd \xXYZ abcd $$@#%^&*!~,.:;?: !!Hello, World 
+           ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
+-- search string has found '1' times
+
+--- Iteration 19 ---
+-- String after replacing the search value is => --
+string(194) "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE\0
+           \00FOUNDD\0abcd \xXYZ abcd $$@#%^&*!~,.:;?: !!Hello, World 
+           ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
+-- search string has found '1' times
+
+--- Iteration 20 ---
+-- String after replacing the search value is => --
+string(194) "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE\0
+           FOUND«CD\0abcd \xXYZ abcd $$@#%^&*!~,.:;?: !!Hello, World 
+           ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
+-- search string has found '1' times
+
+--- Iteration 21 ---
+-- String after replacing the search value is => --
+string(194) "Hello, world,0120333FOUND445-1.234567          NULL TRUE FALSE\0
+           \00«CD\0abcd \xXYZ    abcd $$@#%^&*!~,.:;?: !!Hello, World 
+           ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
+-- search string has found '1' times
+
+--- Iteration 22 ---
+-- String after replacing the search value is => --
+string(203) "Hello, world,0FOUND20333.3445-FOUND.234567          NULL TRUE FALSE\0
+           \00«CD\0abcd \xXYZ    abcd $$@#%^&*!~,.:;?: !!Hello, World 
+           ?Hello, World chr(0).chr(FOUND28).chr(234).chr(65).chr(255).chr(256)"
+-- search string has found '3' times
+
+--- Iteration 23 ---
+-- String after replacing the search value is => --
+string(192) "Hello, world,0120333.3445-1.234567          NULL FOUND FALSE\0
+           \00«CD\0abcd \xXYZ    abcd $$@#%^&*!~,.:;?: !!Hello, World 
+           ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
+-- search string has found '1' times
+
+--- Iteration 24 ---
+-- String after replacing the search value is => --
+string(203) "Hello, world,0FOUND20333.3445-FOUND.234567          NULL TRUE FALSE\0
+           \00«CD\0abcd \xXYZ    abcd $$@#%^&*!~,.:;?: !!Hello, World 
+           ?Hello, World chr(0).chr(FOUND28).chr(234).chr(65).chr(255).chr(256)"
+-- search string has found '3' times
+
+--- Iteration 25 ---
+-- String after replacing the search value is => --
+string(203) "Hello, world,0FOUND20333.3445-FOUND.234567          NULL TRUE FALSE\0
+           \00«CD\0abcd \xXYZ    abcd $$@#%^&*!~,.:;?: !!Hello, World 
+           ?Hello, World chr(0).chr(FOUND28).chr(234).chr(65).chr(255).chr(256)"
+-- search string has found '3' times
+
+--- Iteration 26 ---
+-- String after replacing the search value is => --
+string(191) "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE\0
+           \00«CD\0abcd \xXYZ    abcd $$@#%^&*!~,.:;?: !!Hello, World 
+           ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
+-- search string has found '0' times
+
+--- Iteration 27 ---
+-- String after replacing the search value is => --
+string(191) "Hello, world,0120333.3445-1.234567          NULL TRUE FOUND\0
+           \00«CD\0abcd \xXYZ    abcd $$@#%^&*!~,.:;?: !!Hello, World 
+           ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
+-- search string has found '1' times
+
+--- Iteration 28 ---
+-- String after replacing the search value is => --
+string(307) "Hello,FOUNDworld,0120333.3445-1.234567FOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUNDNULLFOUNDTRUEFOUNDFALSE\0
+FOUND  FOUNDFOUNDFOUNDFOUND\00«CD\0abcdFOUND\xXYZ        abcdFOUND$$@#%^&*!~,.:;?:FOUND!!Hello,FOUNDWorldFOUND
+       FOUNDFOUNDFOUNDFOUND?Hello,FOUNDWorldFOUNDchr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
+-- search string has found '29' times
+
+--- Iteration 29 ---
+-- String after replacing the search value is => --
+string(186) "Hello, world,0120333.3445-1.234567FOUNDNULL TRUE FALSE\0
+           \00«CD\0abcd \xXYZ    abcd $$@#%^&*!~,.:;?: !!Hello, World 
+           ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
+-- search string has found '1' times
+
+--- Iteration 30 ---
+-- String after replacing the search value is => --
+string(199) "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE\0
+           \00«CD\0aFOUNDcd \xXYZ        aFOUNDcd $$@#%^&*!~,.:;?: !!Hello, World 
+           ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
+-- search string has found '2' times
+
+--- Iteration 31 ---
+-- String after replacing the search value is => --
+string(191) "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE\0
+           \00«CD\0abcd \xXYZ    abcd $$@#%^&*!~,.:;?: !!Hello, World 
+           ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
+-- search string has found '0' times
+
+--- Iteration 32 ---
+-- String after replacing the search value is => --
+string(203) "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE\0
+ FOUND    \00«CD\0abcd \xXYZFOUNDabcd $$@#%^&*!~,.:;?: !!Hello, World 
+FOUND    ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
+-- search string has found '3' times
+
+--- Iteration 33 ---
+-- String after replacing the search value is => --
+string(191) "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE\0
+           \00«CD\0abcd \xXYZ    abcd $$@#%^&*!~,.:;?: !!Hello, World 
+           ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
+-- search string has found '0' times
+
+--- Iteration 34 ---
+-- String after replacing the search value is => --
+string(5) "FOUND"
+-- search string has found '1' times
+
+*** Testing Miscelleneous input data ***
+string(3) "qqq"
+int(5)
+array(3) {
+  [0]=>
+  string(3) "qqq"
+  [1]=>
+  string(0) ""
+  [2]=>
+  string(3) "ccc"
+}
+int(6)
+
+-- Testing objects --
+string(12) "Hello, world"
+int(1)
+
+-- Testing arrays --
+string(15) "multimultimulti"
 int(3)
-unicode(3) "qqq"
+string(3) "qqq"
 int(3)
 array(2) {
   [0]=>
-  unicode(3) "qqq"
+  string(3) "qqq"
   [1]=>
-  unicode(3) "ccc"
+  string(3) "ccc"
 }
 int(6)
 
 Notice: Array to string conversion in %s on line %d
 array(2) {
   [0]=>
-  unicode(15) "ArrayArrayArray"
+  string(15) "ArrayArrayArray"
   [1]=>
-  unicode(3) "bbb"
+  string(3) "bbb"
 }
 int(3)
 array(2) {
   [0]=>
-  unicode(3) "111"
+  string(3) "111"
   [1]=>
-  unicode(3) "bbb"
+  string(3) "bbb"
 }
 int(3)
 array(2) {
   [0]=>
-  unicode(4) "aaa3"
+  string(4) "aaa3"
   [1]=>
-  unicode(4) "2bbb"
+  string(4) "2bbb"
 }
 int(1)
-unicode(%d) "Resource id #%d"
-int(1)
+
+-- Testing Resources --
+string(14) "Resource id #6"
+int(0)
+string(14) "Resource id #7"
+int(0)
+
+-- Testing a longer and heredoc string --
+string(623) "FOUNDghijklmnopqrstuvwxyz0123456789FOUNDghijklmnopqrstuvwxyz0123456789
+FOUNDghijklmnopqrstuvwxyz0123456789FOUNDghijklmnopqrstuvwxyz0123456789
+FOUNDghijklmnopqrstuvwxyz0123456789FOUNDghijklmnopqrstuvwxyz0123456789
+FOUNDghijklmnopqrstuvwxyz0123456789FOUNDghijklmnopqrstuvwxyz0123456789
+FOUNDghijklmnopqrstuvwxyz0123456789FOUNDghijklmnopqrstuvwxyz0123456789
+FOUNDghijklmnopqrstuvwxyz0123456789FOUNDghijklmnopqrstuvwxyz0123456789
+FOUNDghijklmnopqrstuvwxyz0123456789FOUNDghijklmnopqrstuvwxyz0123456789
+@#$%^&**&^%$#@!~:())))((((&&&**%$###@@@!!!~~~~@###$%^&*
+FOUNDghijklmnopqrstuvwxyz0123456789FOUNDghijklmnopqrstuvwxyz0123456789"
+int(16)
+
+-- Testing a heredoc null string --
+string(0) ""
+int(0)
+
+-- Testing simple and complex syntax strings --
+string(5) "FOUND"
+string(5) "FOUND"
+
+Notice: Undefined variable: strS in %s on line %d
+string(0) ""
+string(5) "FOUND"
+string(5) "FOUND"
+
+*** Testing error conditions ***
+Warning: str_replace() expects at least 3 parameters, 0 given in %s on line %d
+NULL
+
+Warning: str_replace() expects at least 3 parameters, 1 given in %s on line %d
+NULL
+
+Warning: str_replace() expects at least 3 parameters, 1 given in %s on line %d
+NULL
+
+Warning: str_replace() expects at least 3 parameters, 2 given in %s on line %d
+NULL
+
+Warning: str_replace() expects at most 4 parameters, 5 given in %s on line %d
+NULL
 Done
index 4d30e9822923f103a251d1eb4f8440e983edf1a2..9bd27bc95fb9bc02ed4063d7babb62f37f1fbef0 100644 (file)
Binary files a/ext/standard/tests/strings/strpos.phpt and b/ext/standard/tests/strings/strpos.phpt differ
index 85e832e69e9238570155610b51b6da574ed4b70b..84448332165ed7900e9aa8b109156cb8e02d0b8c 100644 (file)
Binary files a/ext/standard/tests/strings/strstr.phpt and b/ext/standard/tests/strings/strstr.phpt differ
diff --git a/ext/standard/tests/strings/substr.phpt b/ext/standard/tests/strings/substr.phpt
new file mode 100644 (file)
index 0000000..b4dff84
Binary files /dev/null and b/ext/standard/tests/strings/substr.phpt differ
index 6aee365340ed7891966279ca17da199456f5673a..3581aa5b8ba8b4b84ca190cee13b9eb2445d6a42 100644 (file)
@@ -1,23 +1,99 @@
 --TEST--
-substr_count() function
+Test substr_count() function
 --FILE--
 <?php
-       var_dump(@substr_count("", ""));
-       var_dump(@substr_count("a", ""));
-       var_dump(@substr_count("", "a"));
-       var_dump(@substr_count("", "a"));
-       var_dump(@substr_count("", chr(0)));
+/* Prototype: int substr_count ( string $haystack, string $needle [, int $offset [, int $length]] );
+ * Description: substr_count() returns the number of times the needle substring occurs in the 
+ *               haystack string. Please note that needle is case sensitive
+ */
+
+/* Count the number of substring occurrences */
+echo "***Testing basic operations ***\n";
+var_dump(@substr_count("", ""));
+var_dump(@substr_count("a", ""));
+var_dump(@substr_count("", "a"));
+var_dump(@substr_count("", "a"));
+var_dump(@substr_count("", chr(0)));
+$a = str_repeat("abcacba", 100);
+var_dump(@substr_count($a, "bca"));
+$a = str_repeat("abcacbabca", 100);
+var_dump(@substr_count($a, "bca"));
+var_dump(substr_count($a, "bca", 200));
+var_dump(substr_count($a, "bca", 200, 50));
+
+echo "\n*** Testing possible variations ***\n";
+echo "-- 3rd or 4th arg as string --\n";
+$str = "this is a string";
+var_dump( substr_count($str, "t", "5") );
+var_dump( substr_count($str, "t", "5", "10") );
+var_dump( substr_count($str, "i", "5t") );
+var_dump( substr_count($str, "i", "5t", "10t") );
+
+echo "\n-- 3rd or 4th arg as NULL --\n";
+var_dump( substr_count($str, "t", "") );
+var_dump( substr_count($str, "T", "") );
+var_dump( substr_count($str, "t", "", 15) );
+var_dump( substr_count($str, "I", NULL) );
+var_dump( substr_count($str, "i", NULL, 10) );
+
+echo "\n-- overlapped substrings --\n";
+var_dump( substr_count("abcabcabcabcabc", "abca") ); 
+var_dump( substr_count("abcabcabcabcabc", "abca", 2) ); 
+
+echo "\n-- complex strings containing other than 7-bit chars --\n";
+$str = chr(128).chr(129).chr(128).chr(256).chr(255).chr(254).chr(255);
+var_dump(substr_count($str, chr(128)));
+var_dump(substr_count($str, chr(255)));
+var_dump(substr_count($str, chr(256)));
+
+echo "\n-- heredoc string --\n";
+$string = <<<EOD
+abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
+abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
+acdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
+acdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
+abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
+abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
+abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
+abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
+EOD;
+var_dump(substr_count($string, "abcd"));
+var_dump(substr_count($string, "1234"));
+
+echo "\n-- heredoc null string --\n";
+$str = <<<EOD
+EOD;
+var_dump(substr_count($str, "\0"));
+var_dump(substr_count($str, "\x000"));
+var_dump(substr_count($str, "0"));
+
+
+echo "\n*** Testing error conditions ***\n";
+/* Zero argument */
+var_dump( substr_count() );
+
+/* more than expected no. of args */
+var_dump( substr_count($str, "t", 0, 15, 30) );
        
-       $a = str_repeat("abcacba", 100);
-       var_dump(@substr_count($a, "bca"));
+/* offset as negative value */
+var_dump(substr_count($str, "t", -5));
+
+/* offset > size of the string */
+var_dump(substr_count($str, "t", 25));
+
+/* Using offset and length to go beyond the size of the string: 
+   Warning message expected, as length+offset > length of string */
+var_dump( substr_count($str, "i", 5, 15) );
+
+/* length as Null */
+var_dump( substr_count($str, "t", "", "") );
+var_dump( substr_count($str, "i", NULL, NULL) );
        
-       $a = str_repeat("abcacbabca", 100);
-       var_dump(@substr_count($a, "bca"));
+echo "Done\n"; 
 
-       var_dump(substr_count($a, "bca", 200));
-       var_dump(substr_count($a, "bca", 200, 50));
 ?>
---EXPECT--
+--EXPECTF--
+***Testing basic operations ***
 bool(false)
 bool(false)
 int(0)
@@ -27,3 +103,69 @@ int(100)
 int(200)
 int(160)
 int(10)
+
+*** Testing possible variations ***
+-- 3rd or 4th arg as string --
+int(1)
+int(1)
+
+Notice: A non well formed numeric value encountered in %s on line %d
+int(2)
+
+Notice: A non well formed numeric value encountered in %s on line %d
+
+Notice: A non well formed numeric value encountered in %s on line %d
+int(2)
+
+-- 3rd or 4th arg as NULL --
+
+Warning: substr_count() expects parameter 3 to be long, string given in %s on line %d
+NULL
+
+Warning: substr_count() expects parameter 3 to be long, string given in %s on line %d
+NULL
+
+Warning: substr_count() expects parameter 3 to be long, string given in %s on line %d
+NULL
+int(0)
+int(2)
+
+-- overlapped substrings --
+int(2)
+int(2)
+
+-- complex strings containing other than 7-bit chars --
+int(2)
+int(2)
+int(1)
+
+-- heredoc string --
+int(14)
+int(16)
+
+-- heredoc null string --
+int(0)
+int(0)
+int(0)
+
+*** Testing error conditions ***
+
+Warning: substr_count() expects at least 2 parameters, 0 given in %s on line %d
+NULL
+
+Warning: substr_count() expects at most 4 parameters, 5 given in %s on line %d
+NULL
+
+Warning: substr_count(): Offset should be greater than or equal to 0 in %s on line %d
+bool(false)
+
+Warning: substr_count(): Offset value 25 exceeds string length in %s on line %d
+bool(false)
+
+Warning: substr_count(): Offset value 5 exceeds string length in %s on line %d
+bool(false)
+
+Warning: substr_count() expects parameter 3 to be long, string given in %s on line %d
+NULL
+int(0)
+Done
diff --git a/ext/standard/tests/strings/trim1.phpt b/ext/standard/tests/strings/trim1.phpt
new file mode 100644 (file)
index 0000000..b9323af
Binary files /dev/null and b/ext/standard/tests/strings/trim1.phpt differ