1--TEST--
2Test str_replace() function
3--INI--
4precision=14
5--FILE--
6<?php
7/*
8  Prototype: mixed str_replace(mixed $search, mixed $replace,
9                               mixed $subject [, int &$count]);
10  Description: Replace all occurrences of the search string with
11               the replacement string
12*/
13
14echo "\n*** Testing str_replace() with various subjects ***";
15$subject = "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE\000
16 	    \x000\x5ACD\0abcd \xXYZ\tabcd $$@#%^&*!~,.:;?: !!Hello, World
17	    ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)";
18
19/* needles in an array to be compared in the string $string */
20$search_str = array (
21  "Hello, World",
22  'Hello, World',
23  '!!Hello, World',
24  "??Hello, World",
25  "$@#%^&*!~,.:;?",
26  "123",
27  123,
28  "-1.2345",
29  -1.2344,
30  "abcd",
31  'XYZ',
32  NULL,
33  "NULL",
34  "0",
35  0,
36  "",
37  " ",
38  "\0",
39  "\x000",
40  "\x5AC",
41  "\0000",
42  ".3",
43  TRUE,
44  "TRUE",
45  "1",
46  1,
47  FALSE,
48  "FALSE",
49  " ",
50  "          ",
51  'b',
52  '\t',
53  "\t",
54  chr(128).chr(234).chr(65).chr(255).chr(256),
55  $subject
56);
57
58/* loop through to get the  $string */
59for( $i = 0; $i < count($search_str); $i++ ) {
60  echo "\n--- Iteration $i ---";
61  echo "\n-- String after replacing the search value is => --\n";
62  var_dump( str_replace($search_str[$i], "FOUND", $subject, $count) );
63  echo "-- search string has found '$count' times\n";
64}
65
66?>
67===DONE===
68--EXPECT--
69*** Testing str_replace() with various subjects ***
70--- Iteration 0 ---
71-- String after replacing the search value is => --
72string(177) "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE�
73 	    �0ZCD�abcd \xXYZ	abcd $$@#%^&*!~,.:;?: !!FOUND
74	    ?FOUND chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
75-- search string has found '2' times
76
77--- Iteration 1 ---
78-- String after replacing the search value is => --
79string(177) "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE�
80 	    �0ZCD�abcd \xXYZ	abcd $$@#%^&*!~,.:;?: !!FOUND
81	    ?FOUND chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
82-- search string has found '2' times
83
84--- Iteration 2 ---
85-- String after replacing the search value is => --
86string(182) "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE�
87 	    �0ZCD�abcd \xXYZ	abcd $$@#%^&*!~,.:;?: FOUND
88	    ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
89-- search string has found '1' times
90
91--- Iteration 3 ---
92-- String after replacing the search value is => --
93string(191) "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE�
94 	    �0ZCD�abcd \xXYZ	abcd $$@#%^&*!~,.:;?: !!Hello, World
95	    ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
96-- search string has found '0' times
97
98--- Iteration 4 ---
99-- String after replacing the search value is => --
100string(182) "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE�
101 	    �0ZCD�abcd \xXYZ	abcd $FOUND: !!Hello, World
102	    ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
103-- search string has found '1' times
104
105--- Iteration 5 ---
106-- String after replacing the search value is => --
107string(191) "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE�
108 	    �0ZCD�abcd \xXYZ	abcd $$@#%^&*!~,.:;?: !!Hello, World
109	    ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
110-- search string has found '0' times
111
112--- Iteration 6 ---
113-- String after replacing the search value is => --
114string(191) "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE�
115 	    �0ZCD�abcd \xXYZ	abcd $$@#%^&*!~,.:;?: !!Hello, World
116	    ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
117-- search string has found '0' times
118
119--- Iteration 7 ---
120-- String after replacing the search value is => --
121string(189) "Hello, world,0120333.3445FOUND67          NULL TRUE FALSE�
122 	    �0ZCD�abcd \xXYZ	abcd $$@#%^&*!~,.:;?: !!Hello, World
123	    ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
124-- search string has found '1' times
125
126--- Iteration 8 ---
127-- String after replacing the search value is => --
128string(191) "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE�
129 	    �0ZCD�abcd \xXYZ	abcd $$@#%^&*!~,.:;?: !!Hello, World
130	    ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
131-- search string has found '0' times
132
133--- Iteration 9 ---
134-- String after replacing the search value is => --
135string(193) "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE�
136 	    �0ZCD�FOUND \xXYZ	FOUND $$@#%^&*!~,.:;?: !!Hello, World
137	    ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
138-- search string has found '2' times
139
140--- Iteration 10 ---
141-- String after replacing the search value is => --
142string(193) "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE�
143 	    �0ZCD�abcd \xFOUND	abcd $$@#%^&*!~,.:;?: !!Hello, World
144	    ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
145-- search string has found '1' times
146
147--- Iteration 11 ---
148-- String after replacing the search value is => --
149string(191) "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE�
150 	    �0ZCD�abcd \xXYZ	abcd $$@#%^&*!~,.:;?: !!Hello, World
151	    ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
152-- search string has found '0' times
153
154--- Iteration 12 ---
155-- String after replacing the search value is => --
156string(192) "Hello, world,0120333.3445-1.234567          FOUND TRUE FALSE�
157 	    �0ZCD�abcd \xXYZ	abcd $$@#%^&*!~,.:;?: !!Hello, World
158	    ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
159-- search string has found '1' times
160
161--- Iteration 13 ---
162-- String after replacing the search value is => --
163string(207) "Hello, world,FOUND12FOUND333.3445-1.234567          NULL TRUE FALSE�
164 	    �FOUNDZCD�abcd \xXYZ	abcd $$@#%^&*!~,.:;?: !!Hello, World
165	    ?Hello, World chr(FOUND).chr(128).chr(234).chr(65).chr(255).chr(256)"
166-- search string has found '4' times
167
168--- Iteration 14 ---
169-- String after replacing the search value is => --
170string(207) "Hello, world,FOUND12FOUND333.3445-1.234567          NULL TRUE FALSE�
171 	    �FOUNDZCD�abcd \xXYZ	abcd $$@#%^&*!~,.:;?: !!Hello, World
172	    ?Hello, World chr(FOUND).chr(128).chr(234).chr(65).chr(255).chr(256)"
173-- search string has found '4' times
174
175--- Iteration 15 ---
176-- String after replacing the search value is => --
177string(191) "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE�
178 	    �0ZCD�abcd \xXYZ	abcd $$@#%^&*!~,.:;?: !!Hello, World
179	    ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
180-- search string has found '0' times
181
182--- Iteration 16 ---
183-- String after replacing the search value is => --
184string(307) "Hello,FOUNDworld,0120333.3445-1.234567FOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUNDNULLFOUNDTRUEFOUNDFALSE�
185FOUND	FOUNDFOUNDFOUNDFOUND�0ZCD�abcdFOUND\xXYZ	abcdFOUND$$@#%^&*!~,.:;?:FOUND!!Hello,FOUNDWorldFOUND
186	FOUNDFOUNDFOUNDFOUND?Hello,FOUNDWorldFOUNDchr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
187-- search string has found '29' times
188
189--- Iteration 17 ---
190-- String after replacing the search value is => --
191string(203) "Hello, world,0120333.3445-1.234567          NULL TRUE FALSEFOUND
192 	    FOUND0ZCDFOUNDabcd \xXYZ	abcd $$@#%^&*!~,.:;?: !!Hello, World
193	    ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
194-- search string has found '3' times
195
196--- Iteration 18 ---
197-- String after replacing the search value is => --
198string(194) "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE�
199 	    FOUNDZCD�abcd \xXYZ	abcd $$@#%^&*!~,.:;?: !!Hello, World
200	    ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
201-- search string has found '1' times
202
203--- Iteration 19 ---
204-- String after replacing the search value is => --
205string(194) "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE�
206 	    �0FOUNDD�abcd \xXYZ	abcd $$@#%^&*!~,.:;?: !!Hello, World
207	    ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
208-- search string has found '1' times
209
210--- Iteration 20 ---
211-- String after replacing the search value is => --
212string(194) "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE�
213 	    FOUNDZCD�abcd \xXYZ	abcd $$@#%^&*!~,.:;?: !!Hello, World
214	    ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
215-- search string has found '1' times
216
217--- Iteration 21 ---
218-- String after replacing the search value is => --
219string(194) "Hello, world,0120333FOUND445-1.234567          NULL TRUE FALSE�
220 	    �0ZCD�abcd \xXYZ	abcd $$@#%^&*!~,.:;?: !!Hello, World
221	    ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
222-- search string has found '1' times
223
224--- Iteration 22 ---
225-- String after replacing the search value is => --
226string(203) "Hello, world,0FOUND20333.3445-FOUND.234567          NULL TRUE FALSE�
227 	    �0ZCD�abcd \xXYZ	abcd $$@#%^&*!~,.:;?: !!Hello, World
228	    ?Hello, World chr(0).chr(FOUND28).chr(234).chr(65).chr(255).chr(256)"
229-- search string has found '3' times
230
231--- Iteration 23 ---
232-- String after replacing the search value is => --
233string(192) "Hello, world,0120333.3445-1.234567          NULL FOUND FALSE�
234 	    �0ZCD�abcd \xXYZ	abcd $$@#%^&*!~,.:;?: !!Hello, World
235	    ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
236-- search string has found '1' times
237
238--- Iteration 24 ---
239-- String after replacing the search value is => --
240string(203) "Hello, world,0FOUND20333.3445-FOUND.234567          NULL TRUE FALSE�
241 	    �0ZCD�abcd \xXYZ	abcd $$@#%^&*!~,.:;?: !!Hello, World
242	    ?Hello, World chr(0).chr(FOUND28).chr(234).chr(65).chr(255).chr(256)"
243-- search string has found '3' times
244
245--- Iteration 25 ---
246-- String after replacing the search value is => --
247string(203) "Hello, world,0FOUND20333.3445-FOUND.234567          NULL TRUE FALSE�
248 	    �0ZCD�abcd \xXYZ	abcd $$@#%^&*!~,.:;?: !!Hello, World
249	    ?Hello, World chr(0).chr(FOUND28).chr(234).chr(65).chr(255).chr(256)"
250-- search string has found '3' times
251
252--- Iteration 26 ---
253-- String after replacing the search value is => --
254string(191) "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE�
255 	    �0ZCD�abcd \xXYZ	abcd $$@#%^&*!~,.:;?: !!Hello, World
256	    ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
257-- search string has found '0' times
258
259--- Iteration 27 ---
260-- String after replacing the search value is => --
261string(191) "Hello, world,0120333.3445-1.234567          NULL TRUE FOUND�
262 	    �0ZCD�abcd \xXYZ	abcd $$@#%^&*!~,.:;?: !!Hello, World
263	    ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
264-- search string has found '1' times
265
266--- Iteration 28 ---
267-- String after replacing the search value is => --
268string(307) "Hello,FOUNDworld,0120333.3445-1.234567FOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUNDFOUNDNULLFOUNDTRUEFOUNDFALSE�
269FOUND	FOUNDFOUNDFOUNDFOUND�0ZCD�abcdFOUND\xXYZ	abcdFOUND$$@#%^&*!~,.:;?:FOUND!!Hello,FOUNDWorldFOUND
270	FOUNDFOUNDFOUNDFOUND?Hello,FOUNDWorldFOUNDchr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
271-- search string has found '29' times
272
273--- Iteration 29 ---
274-- String after replacing the search value is => --
275string(186) "Hello, world,0120333.3445-1.234567FOUNDNULL TRUE FALSE�
276 	    �0ZCD�abcd \xXYZ	abcd $$@#%^&*!~,.:;?: !!Hello, World
277	    ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
278-- search string has found '1' times
279
280--- Iteration 30 ---
281-- String after replacing the search value is => --
282string(199) "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE�
283 	    �0ZCD�aFOUNDcd \xXYZ	aFOUNDcd $$@#%^&*!~,.:;?: !!Hello, World
284	    ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
285-- search string has found '2' times
286
287--- Iteration 31 ---
288-- String after replacing the search value is => --
289string(191) "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE�
290 	    �0ZCD�abcd \xXYZ	abcd $$@#%^&*!~,.:;?: !!Hello, World
291	    ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
292-- search string has found '0' times
293
294--- Iteration 32 ---
295-- String after replacing the search value is => --
296string(203) "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE�
297 FOUND    �0ZCD�abcd \xXYZFOUNDabcd $$@#%^&*!~,.:;?: !!Hello, World
298FOUND    ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
299-- search string has found '3' times
300
301--- Iteration 33 ---
302-- String after replacing the search value is => --
303string(191) "Hello, world,0120333.3445-1.234567          NULL TRUE FALSE�
304 	    �0ZCD�abcd \xXYZ	abcd $$@#%^&*!~,.:;?: !!Hello, World
305	    ?Hello, World chr(0).chr(128).chr(234).chr(65).chr(255).chr(256)"
306-- search string has found '0' times
307
308--- Iteration 34 ---
309-- String after replacing the search value is => --
310string(5) "FOUND"
311-- search string has found '1' times
312===DONE===