Annotation of embedaddon/php/ext/standard/tests/strings/stripslashes_variation2.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test stripslashes() function : usage variations - un-quote strings quoted with addslashes()
3: --FILE--
4: <?php
5: /* Prototype : string stripslashes ( string $str )
6: * Description: Returns an un-quoted string
7: * Source code: ext/standard/string.c
8: */
9:
10: /*
11: * Test stripslashes() with various strings containing characters thats can be backslashed.
12: * First adding slashes using addslashes() and then removing the slashes using stripslashes()
13: */
14:
15: echo "*** Testing stripslashes() : with various strings containing backslashed characters ***\n";
16:
17: // initialising a heredoc string
18: $heredoc_string = <<<EOT
19: This is line 1 of 'heredoc' string
20: This is line 2 of "heredoc" string
21: EOT;
22:
23: $heredoc_null_string =<<<EOT
24: EOT;
25: $heredoc_string_only_backslash =<<<EOT
26: \
27: EOT;
28: $heredoc_string_only_single_quote =<<<EOT
29: '
30: EOT;
31: $heredoc_string_only_double_quote =<<<EOT
32: "
33: EOT;
34:
35: // initialising the string array
36:
37: $str_array = array(
38: // string without any characters that can be backslashed
39: 'Hello world',
40:
41: // string with single quotes
42: "how're you doing?",
43: "don't disturb u'r neighbours",
44: "don't disturb u'r neighbours''",
45: '',
46: '\'',
47: "'",
48: $heredoc_string_only_single_quote,
49:
50: // string with double quotes
51: 'he said, "he will be on leave"',
52: 'he said, ""he will be on leave"',
53: '"""PHP"""',
54: "",
55: "\"",
56: '"',
57: "hello\"",
58: $heredoc_string_only_double_quote,
59:
60: // string with backslash characters
61: 'Is your name Ram\Krishna?',
62: '\\0.0.0.0',
63: 'c:\php\testcase\stripslashes',
64: '\\',
65: $heredoc_string_only_backslash,
66:
67: // string with nul characters
68: 'hello'.chr(0).'world',
69: chr(0).'hello'.chr(0),
70: chr(0).chr(0).'hello',
71: chr(0),
72:
73: // mixed strings
74: "'\\0.0.0.0'",
75: "'\\0.0.0.0'".chr(0),
76: chr(0)."'c:\php\'",
77: '"\\0.0.0.0"',
78: '"c:\php\"'.chr(0)."'",
79: '"hello"'."'world'".chr(0).'//',
80:
81: // string with hexadecimal number
82: "0xABCDEF0123456789",
83: "\x00",
84: '!@#$%&*@$%#&/;:,<>',
85: "hello\x00world",
86:
87: // heredoc strings
88: $heredoc_string,
89: $heredoc_null_string
90: );
91:
92: $count = 1;
93: // looping to test for all strings in $str_array
94: foreach( $str_array as $str ) {
95: echo "\n-- Iteration $count --\n";
96: $str_addslashes = addslashes($str);
97: var_dump("The string after addslashes is:", $str_addslashes);
98: $str_stripslashes = stripslashes($str_addslashes);
99: var_dump("The string after stripslashes is:", $str_stripslashes);
100: if( strcmp($str, $str_stripslashes) != 0 )
101: echo "\nError: Original string and string from stripslash() donot match\n";
102: $count ++;
103: }
104:
105: echo "Done\n";
106: ?>
107: --EXPECTF--
108: *** Testing stripslashes() : with various strings containing backslashed characters ***
109:
110: -- Iteration 1 --
111: string(31) "The string after addslashes is:"
112: string(11) "Hello world"
113: string(33) "The string after stripslashes is:"
114: string(11) "Hello world"
115:
116: -- Iteration 2 --
117: string(31) "The string after addslashes is:"
118: string(18) "how\'re you doing?"
119: string(33) "The string after stripslashes is:"
120: string(17) "how're you doing?"
121:
122: -- Iteration 3 --
123: string(31) "The string after addslashes is:"
124: string(30) "don\'t disturb u\'r neighbours"
125: string(33) "The string after stripslashes is:"
126: string(28) "don't disturb u'r neighbours"
127:
128: -- Iteration 4 --
129: string(31) "The string after addslashes is:"
130: string(34) "don\'t disturb u\'r neighbours\'\'"
131: string(33) "The string after stripslashes is:"
132: string(30) "don't disturb u'r neighbours''"
133:
134: -- Iteration 5 --
135: string(31) "The string after addslashes is:"
136: string(0) ""
137: string(33) "The string after stripslashes is:"
138: string(0) ""
139:
140: -- Iteration 6 --
141: string(31) "The string after addslashes is:"
142: string(2) "\'"
143: string(33) "The string after stripslashes is:"
144: string(1) "'"
145:
146: -- Iteration 7 --
147: string(31) "The string after addslashes is:"
148: string(2) "\'"
149: string(33) "The string after stripslashes is:"
150: string(1) "'"
151:
152: -- Iteration 8 --
153: string(31) "The string after addslashes is:"
154: string(2) "\'"
155: string(33) "The string after stripslashes is:"
156: string(1) "'"
157:
158: -- Iteration 9 --
159: string(31) "The string after addslashes is:"
160: string(32) "he said, \"he will be on leave\""
161: string(33) "The string after stripslashes is:"
162: string(30) "he said, "he will be on leave""
163:
164: -- Iteration 10 --
165: string(31) "The string after addslashes is:"
166: string(34) "he said, \"\"he will be on leave\""
167: string(33) "The string after stripslashes is:"
168: string(31) "he said, ""he will be on leave""
169:
170: -- Iteration 11 --
171: string(31) "The string after addslashes is:"
172: string(15) "\"\"\"PHP\"\"\""
173: string(33) "The string after stripslashes is:"
174: string(9) """"PHP""""
175:
176: -- Iteration 12 --
177: string(31) "The string after addslashes is:"
178: string(0) ""
179: string(33) "The string after stripslashes is:"
180: string(0) ""
181:
182: -- Iteration 13 --
183: string(31) "The string after addslashes is:"
184: string(2) "\""
185: string(33) "The string after stripslashes is:"
186: string(1) """
187:
188: -- Iteration 14 --
189: string(31) "The string after addslashes is:"
190: string(2) "\""
191: string(33) "The string after stripslashes is:"
192: string(1) """
193:
194: -- Iteration 15 --
195: string(31) "The string after addslashes is:"
196: string(7) "hello\""
197: string(33) "The string after stripslashes is:"
198: string(6) "hello""
199:
200: -- Iteration 16 --
201: string(31) "The string after addslashes is:"
202: string(2) "\""
203: string(33) "The string after stripslashes is:"
204: string(1) """
205:
206: -- Iteration 17 --
207: string(31) "The string after addslashes is:"
208: string(26) "Is your name Ram\\Krishna?"
209: string(33) "The string after stripslashes is:"
210: string(25) "Is your name Ram\Krishna?"
211:
212: -- Iteration 18 --
213: string(31) "The string after addslashes is:"
214: string(9) "\\0.0.0.0"
215: string(33) "The string after stripslashes is:"
216: string(8) "\0.0.0.0"
217:
218: -- Iteration 19 --
219: string(31) "The string after addslashes is:"
220: string(31) "c:\\php\\testcase\\stripslashes"
221: string(33) "The string after stripslashes is:"
222: string(28) "c:\php\testcase\stripslashes"
223:
224: -- Iteration 20 --
225: string(31) "The string after addslashes is:"
226: string(2) "\\"
227: string(33) "The string after stripslashes is:"
228: string(1) "\"
229:
230: -- Iteration 21 --
231: string(31) "The string after addslashes is:"
232: string(2) "\\"
233: string(33) "The string after stripslashes is:"
234: string(1) "\"
235:
236: -- Iteration 22 --
237: string(31) "The string after addslashes is:"
238: string(12) "hello\0world"
239: string(33) "The string after stripslashes is:"
240: string(11) "hello world"
241:
242: -- Iteration 23 --
243: string(31) "The string after addslashes is:"
244: string(9) "\0hello\0"
245: string(33) "The string after stripslashes is:"
246: string(7) "