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