File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / strings / str_replace_variation2.phpt
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue Feb 21 23:48:04 2012 UTC (12 years, 5 months ago) by misho
Branches: php, MAIN
CVS tags: v5_4_3elwix, v5_4_29p0, v5_4_29, v5_4_20p0, v5_4_20, v5_4_17p0, v5_4_17, v5_3_10, HEAD
php

--TEST--
Test str_replace() function
--INI--
precision=14
--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
*/

echo "\n*** Testing str_replace() with various subjects ***";
$subject = "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE\000
 	    \x000\x5ACD\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",
  "\x5AC",
  "\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";
}

?>
===DONE===
--EXPECT--	
*** 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
 	    0ZCDabcd \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
 	    0ZCDabcd \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
 	    0ZCDabcd \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
 	    0ZCDabcd \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
 	    0ZCDabcd \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
 	    0ZCDabcd \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
 	    0ZCDabcd \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
 	    0ZCDabcd \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
 	    0ZCDabcd \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
 	    0ZCDFOUND \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
 	    0ZCDabcd \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
 	    0ZCDabcd \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
 	    0ZCDabcd \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
 	    FOUNDZCDabcd \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
 	    FOUNDZCDabcd \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
 	    0ZCDabcd \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
FOUND	FOUNDFOUNDFOUNDFOUND0ZCDabcdFOUND\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
 	    FOUND0ZCDFOUNDabcd \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
 	    FOUNDZCDabcd \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
 	    0FOUNDDabcd \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
 	    FOUNDZCDabcd \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
 	    0ZCDabcd \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
 	    0ZCDabcd \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
 	    0ZCDabcd \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
 	    0ZCDabcd \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
 	    0ZCDabcd \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
 	    0ZCDabcd \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
 	    0ZCDabcd \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
FOUND	FOUNDFOUNDFOUNDFOUND0ZCDabcdFOUND\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
 	    0ZCDabcd \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
 	    0ZCDaFOUNDcd \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
 	    0ZCDabcd \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
 FOUND    0ZCDabcd \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
 	    0ZCDabcd \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
===DONE===

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>