Annotation of embedaddon/php/ext/standard/tests/strings/chop_variation4.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test chop() function : usage variations - strings with embedded nulls
3: --FILE--
4: <?php
5: /* Prototype : string chop ( string $str [, string $charlist] )
6: * Description: Strip whitespace (or other characters) from the end of a string
7: * Source code: ext/standard/string.c
8: */
9:
10: /*
11: * Testing chop() : with nulls embedded in input string
12: */
13:
14: echo "*** Testing chop() : string with embedded nulls ***\n";
15:
16: // defining varous strings with embedded nulls
17: $strings_with_nulls = array(
18: "hello\0world",
19: "\0hello",
20: "hello\0",
21: "\0\0hello\tworld\0\0",
22: "\\0hello\\0",
23: 'hello\0\0',
24: chr(0),
25: chr(0).chr(0),
26: chr(0).'hello'.chr(0),
27: 'hello'.chr(0).'world'
28: );
29:
30: $count = 1;
31: foreach($strings_with_nulls as $string) {
32: echo "\n--- Iteration $count ---\n";
33: var_dump( chop($string) );
34: var_dump( chop($string, "\0") );
35: var_dump( chop($string, '\0') );
36: $count++;
37: }
38:
39: echo "Done\n";
40: ?>
41: --EXPECTF--
42: *** Testing chop() : string with embedded nulls ***
43:
44: --- Iteration 1 ---
45: string(11) "hello world"
46: string(11) "hello world"
47: string(11) "hello world"
48:
49: --- Iteration 2 ---
50: string(6) "