1--TEST--
2Test 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
14echo "*** 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;
31foreach($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
39echo "Done\n";
40?>
41--EXPECT--
42*** Testing chop() : string with embedded nulls ***
43
44--- Iteration 1 ---
45string(11) "hello�world"
46string(11) "hello�world"
47string(11) "hello�world"
48
49--- Iteration 2 ---
50string(6) "�hello"
51string(6) "�hello"
52string(6) "�hello"
53
54--- Iteration 3 ---
55string(5) "hello"
56string(5) "hello"
57string(6) "hello�"
58
59--- Iteration 4 ---
60string(13) "��hello	world"
61string(13) "��hello	world"
62string(15) "��hello	world��"
63
64--- Iteration 5 ---
65string(9) "\0hello\0"
66string(9) "\0hello\0"
67string(7) "\0hello"
68
69--- Iteration 6 ---
70string(9) "hello\0\0"
71string(9) "hello\0\0"
72string(5) "hello"
73
74--- Iteration 7 ---
75string(0) ""
76string(0) ""
77string(1) "�"
78
79--- Iteration 8 ---
80string(0) ""
81string(0) ""
82string(2) "��"
83
84--- Iteration 9 ---
85string(6) "�hello"
86string(6) "�hello"
87string(7) "�hello�"
88
89--- Iteration 10 ---
90string(11) "hello�world"
91string(11) "hello�world"
92string(11) "hello�world"
93Done
94