php-src/ext/standard/tests/strings/str_replace_variation2.phpt
Peter Kokot d679f02295 Sync leading and final newlines in *.phpt sections
This patch adds missing newlines, trims multiple redundant final
newlines into a single one, and trims redundant leading newlines in all
*.phpt sections.

According to POSIX, a line is a sequence of zero or more non-' <newline>'
characters plus a terminating '<newline>' character. [1] Files should
normally have at least one final newline character.

C89 [2] and later standards [3] mention a final newline:
"A source file that is not empty shall end in a new-line character,
which shall not be immediately preceded by a backslash character."

Although it is not mandatory for all files to have a final newline
fixed, a more consistent and homogeneous approach brings less of commit
differences issues and a better development experience in certain text
editors and IDEs.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_206
[2] https://port70.net/~nsz/c/c89/c89-draft.html#2.1.1.2
[3] https://port70.net/~nsz/c/c99/n1256.html#5.1.1.2
2018-10-15 04:33:09 +02:00

313 lines
12 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

--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===