1--TEST--
2Test chop() function : usage variations - strings with embedded nulls
3--FILE--
4<?php
5/*
6 * Testing chop() : with nulls embedded in input string
7*/
8
9echo "*** Testing chop() : string with embedded nulls ***\n";
10
11// defining varous strings with embedded nulls
12$strings_with_nulls = array(
13               "hello\0world",
14               "\0hello",
15               "hello\0",
16               "\0\0hello\tworld\0\0",
17               "\\0hello\\0",
18               'hello\0\0',
19               chr(0),
20               chr(0).chr(0),
21                   chr(0).'hello'.chr(0),
22               'hello'.chr(0).'world'
23               );
24
25$count = 1;
26foreach($strings_with_nulls as $string)  {
27  echo "\n--- Iteration $count ---\n";
28  var_dump( chop($string) );
29  var_dump( chop($string, "\0") );
30  var_dump( chop($string, '\0') );
31  $count++;
32}
33
34echo "Done\n";
35?>
36--EXPECTF--
37*** Testing chop() : string with embedded nulls ***
38
39--- Iteration 1 ---
40string(11) "hello%0world"
41string(11) "hello%0world"
42string(11) "hello%0world"
43
44--- Iteration 2 ---
45string(6) "%0hello"
46string(6) "%0hello"
47string(6) "%0hello"
48
49--- Iteration 3 ---
50string(5) "hello"
51string(5) "hello"
52string(6) "hello%0"
53
54--- Iteration 4 ---
55string(13) "%0%0hello	world"
56string(13) "%0%0hello	world"
57string(15) "%0%0hello	world%0%0"
58
59--- Iteration 5 ---
60string(9) "\0hello\0"
61string(9) "\0hello\0"
62string(7) "\0hello"
63
64--- Iteration 6 ---
65string(9) "hello\0\0"
66string(9) "hello\0\0"
67string(5) "hello"
68
69--- Iteration 7 ---
70string(0) ""
71string(0) ""
72string(1) "%0"
73
74--- Iteration 8 ---
75string(0) ""
76string(0) ""
77string(2) "%0%0"
78
79--- Iteration 9 ---
80string(6) "%0hello"
81string(6) "%0hello"
82string(7) "%0hello%0"
83
84--- Iteration 10 ---
85string(11) "hello%0world"
86string(11) "hello%0world"
87string(11) "hello%0world"
88Done
89