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