1--TEST--
2Test addslashes() function : usage variations - with magic_quotes_sybase directive ON
3--FILE--
4<?php
5/* Prototype  : string addslashes ( string $str )
6 * Description: Returns a string with backslashes before characters that need to be quoted in database queries etc.
7 * Source code: ext/standard/string.c
8*/
9
10/*
11 * Test addslashes() with PHP directive magic_quotes_sybase set ON
12*/
13
14echo "*** Testing addslashes() : with php directive magic_quotes_sybase set ON ***\n";
15
16// setting ON the php directive magic_quotes_sybase
17ini_set("magic_quotes_sybase", "1");
18
19// initialising a heredoc string
20$heredoc_string = <<<EOT
21This is line 1 of 'heredoc' string
22This is line 2 of "heredoc" string
23EOT;
24
25$heredoc_null_string =<<<EOT
26EOT;
27
28// initialising the string array
29$str_array = array(
30                    // string without any characters that can be backslashed
31                    'Hello world',
32
33                    // string with single quotes
34                    "how're you doing?",
35                    "don't disturb u'r neighbours",
36                    "don't disturb u'r neighbours''",
37                    '',
38                    '\'',
39                    "'",
40
41                    // string with double quotes
42                    'he said, "he will be on leave"',
43                    'he said, ""he will be on leave"',
44                    '"""PHP"""',
45                    "",
46                    "\"",
47                    '"',
48 		    "hello\"",
49
50                    // string with backslash characters
51                    'Is your name Ram\Krishna?',
52                    '\\0.0.0.0',
53                    'c:\php\testcase\addslashes',
54                    '\\',
55
56                    // string with nul characters
57                    'hello'.chr(0).'world',
58                    chr(0).'hello'.chr(0),
59                    chr(0).chr(0).'hello',
60                    chr(0),
61
62                    // mixed strings
63                    "'\\0.0.0.0'",
64                    "'\\0.0.0.0'".chr(0),
65                    chr(0)."'c:\php\'",
66                    '"\\0.0.0.0"',
67                    '"c:\php\"'.chr(0)."'",
68                    '"hello"'."'world'".chr(0).'//',
69
70		    // string with hexadecimal number
71                    "0xABCDEF0123456789",
72                    "\xabcdef0123456789",
73                    '!@#$%&*@$%#&/;:,<>',
74                    "hello\x00world",
75
76                    // heredoc strings
77                    $heredoc_string,
78                    $heredoc_null_string
79                  );
80
81$count = 1;
82// looping to test for all strings in $str_array
83foreach( $str_array as $str )  {
84  echo "\n-- Iteration $count --\n";
85  var_dump( addslashes($str) );
86  $count ++;
87}
88
89echo "Done\n";
90?>
91--EXPECTF--
92*** Testing addslashes() : with php directive magic_quotes_sybase set ON ***
93
94-- Iteration 1 --
95string(11) "Hello world"
96
97-- Iteration 2 --
98string(18) "how''re you doing?"
99
100-- Iteration 3 --
101string(30) "don''t disturb u''r neighbours"
102
103-- Iteration 4 --
104string(34) "don''t disturb u''r neighbours''''"
105
106-- Iteration 5 --
107string(0) ""
108
109-- Iteration 6 --
110string(2) "''"
111
112-- Iteration 7 --
113string(2) "''"
114
115-- Iteration 8 --
116string(30) "he said, "he will be on leave""
117
118-- Iteration 9 --
119string(31) "he said, ""he will be on leave""
120
121-- Iteration 10 --
122string(9) """"PHP""""
123
124-- Iteration 11 --
125string(0) ""
126
127-- Iteration 12 --
128string(1) """
129
130-- Iteration 13 --
131string(1) """
132
133-- Iteration 14 --
134string(6) "hello""
135
136-- Iteration 15 --
137string(25) "Is your name Ram\Krishna?"
138
139-- Iteration 16 --
140string(8) "\0.0.0.0"
141
142-- Iteration 17 --
143string(26) "c:\php\testcase\addslashes"
144
145-- Iteration 18 --
146string(1) "\"
147
148-- Iteration 19 --
149string(12) "hello\0world"
150
151-- Iteration 20 --
152string(9) "\0hello\0"
153
154-- Iteration 21 --
155string(9) "\0\0hello"
156
157-- Iteration 22 --
158string(2) "\0"
159
160-- Iteration 23 --
161string(12) "''\0.0.0.0''"
162
163-- Iteration 24 --
164string(14) "''\0.0.0.0''\0"
165
166-- Iteration 25 --
167string(13) "\0''c:\php\''"
168
169-- Iteration 26 --
170string(10) ""\0.0.0.0""
171
172-- Iteration 27 --
173string(13) ""c:\php\"\0''"
174
175-- Iteration 28 --
176string(20) ""hello"''world''\0//"
177
178-- Iteration 29 --
179string(18) "0xABCDEF0123456789"
180
181-- Iteration 30 --
182string(15) "�cdef0123456789"
183
184-- Iteration 31 --
185string(18) "!@#$%&*@$%#&/;:,<>"
186
187-- Iteration 32 --
188string(12) "hello\0world"
189
190-- Iteration 33 --
191string(71) "This is line 1 of ''heredoc'' string
192This is line 2 of "heredoc" string"
193
194-- Iteration 34 --
195string(0) ""
196Done
197