1--TEST-- 2Test stripslashes() function : usage variations - with magic_quotes_sybase directive ON 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 PHP directive magic_quotes_sybase set ON 12*/ 13 14echo "*** Testing stripslashes() : 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 'c:\php\testcase\stripslashes', 53 '\\', 54 55 // string with nul characters 56 'hello'.chr(0).'world', 57 chr(0).'hello'.chr(0), 58 chr(0).chr(0).'hello', 59 chr(0), 60 61 // mixed strings 62 "\\\"'0.0.0.0'", 63 "\\\"'0.0.0.0'".chr(0), 64 chr(0)."'c:\php\'", 65 '"c:\php\"'.chr(0)."'", 66 '"hello"'."'world'".chr(0).'//', 67 68 // string with hexadecimal number 69 "0xABCDEF0123456789", 70 "\xabcdef0123456789", 71 '!@#$%&*@$%#&/;:,<>', 72 "hello\x00world", 73 74 // heredoc strings 75 $heredoc_string, 76 $heredoc_null_string 77 ); 78 79$count = 1; 80// looping to test for all strings in $str_array 81foreach( $str_array as $str ) { 82 echo "\n-- Iteration $count --\n"; 83 $str_addslashes = addslashes($str); 84 var_dump("The string after addslashes is:", $str_addslashes); 85 $str_stripslashes = stripslashes($str_addslashes); 86 var_dump("The string after stripslashes is:", $str_stripslashes); 87 if( strcmp($str, $str_stripslashes) != 0 ) 88 echo "\nOriginal string and string from stripslashes() donot match\n"; 89 $count ++; 90} 91 92echo "Done\n"; 93?> 94--EXPECTF-- 95*** Testing stripslashes() : with php directive magic_quotes_sybase set ON *** 96 97-- Iteration 1 -- 98string(31) "The string after addslashes is:" 99string(11) "Hello world" 100string(33) "The string after stripslashes is:" 101string(11) "Hello world" 102 103-- Iteration 2 -- 104string(31) "The string after addslashes is:" 105string(18) "how''re you doing?" 106string(33) "The string after stripslashes is:" 107string(17) "how're you doing?" 108 109-- Iteration 3 -- 110string(31) "The string after addslashes is:" 111string(30) "don''t disturb u''r neighbours" 112string(33) "The string after stripslashes is:" 113string(28) "don't disturb u'r neighbours" 114 115-- Iteration 4 -- 116string(31) "The string after addslashes is:" 117string(34) "don''t disturb u''r neighbours''''" 118string(33) "The string after stripslashes is:" 119string(30) "don't disturb u'r neighbours''" 120 121-- Iteration 5 -- 122string(31) "The string after addslashes is:" 123string(0) "" 124string(33) "The string after stripslashes is:" 125string(0) "" 126 127-- Iteration 6 -- 128string(31) "The string after addslashes is:" 129string(2) "''" 130string(33) "The string after stripslashes is:" 131string(1) "'" 132 133-- Iteration 7 -- 134string(31) "The string after addslashes is:" 135string(2) "''" 136string(33) "The string after stripslashes is:" 137string(1) "'" 138 139-- Iteration 8 -- 140string(31) "The string after addslashes is:" 141string(30) "he said, "he will be on leave"" 142string(33) "The string after stripslashes is:" 143string(30) "he said, "he will be on leave"" 144 145-- Iteration 9 -- 146string(31) "The string after addslashes is:" 147string(31) "he said, ""he will be on leave"" 148string(33) "The string after stripslashes is:" 149string(31) "he said, ""he will be on leave"" 150 151-- Iteration 10 -- 152string(31) "The string after addslashes is:" 153string(9) """"PHP"""" 154string(33) "The string after stripslashes is:" 155string(9) """"PHP"""" 156 157-- Iteration 11 -- 158string(31) "The string after addslashes is:" 159string(0) "" 160string(33) "The string after stripslashes is:" 161string(0) "" 162 163-- Iteration 12 -- 164string(31) "The string after addslashes is:" 165string(1) """ 166string(33) "The string after stripslashes is:" 167string(1) """ 168 169-- Iteration 13 -- 170string(31) "The string after addslashes is:" 171string(1) """ 172string(33) "The string after stripslashes is:" 173string(1) """ 174 175-- Iteration 14 -- 176string(31) "The string after addslashes is:" 177string(6) "hello"" 178string(33) "The string after stripslashes is:" 179string(6) "hello"" 180 181-- Iteration 15 -- 182string(31) "The string after addslashes is:" 183string(25) "Is your name Ram\Krishna?" 184string(33) "The string after stripslashes is:" 185string(25) "Is your name Ram\Krishna?" 186 187-- Iteration 16 -- 188string(31) "The string after addslashes is:" 189string(28) "c:\php\testcase\stripslashes" 190string(33) "The string after stripslashes is:" 191string(28) "c:\php\testcase\stripslashes" 192 193-- Iteration 17 -- 194string(31) "The string after addslashes is:" 195string(1) "\" 196string(33) "The string after stripslashes is:" 197string(1) "\" 198 199-- Iteration 18 -- 200string(31) "The string after addslashes is:" 201string(12) "hello\0world" 202string(33) "The string after stripslashes is:" 203string(11) "helloworld" 204 205-- Iteration 19 -- 206string(31) "The string after addslashes is:" 207string(9) "\0hello\0" 208string(33) "The string after stripslashes is:" 209string(7) "hello" 210 211-- Iteration 20 -- 212string(31) "The string after addslashes is:" 213string(9) "\0\0hello" 214string(33) "The string after stripslashes is:" 215string(7) "hello" 216 217-- Iteration 21 -- 218string(31) "The string after addslashes is:" 219string(2) "\0" 220string(33) "The string after stripslashes is:" 221string(1) "" 222 223-- Iteration 22 -- 224string(31) "The string after addslashes is:" 225string(13) "\"''0.0.0.0''" 226string(33) "The string after stripslashes is:" 227string(11) "\"'0.0.0.0'" 228 229-- Iteration 23 -- 230string(31) "The string after addslashes is:" 231string(15) "\"''0.0.0.0''\0" 232string(33) "The string after stripslashes is:" 233string(12) "\"'0.0.0.0'" 234 235-- Iteration 24 -- 236string(31) "The string after addslashes is:" 237string(13) "\0''c:\php\''" 238string(33) "The string after stripslashes is:" 239string(10) "'c:\php\'" 240 241-- Iteration 25 -- 242string(31) "The string after addslashes is:" 243string(13) ""c:\php\"\0''" 244string(33) "The string after stripslashes is:" 245string(11) ""c:\php\"'" 246 247-- Iteration 26 -- 248string(31) "The string after addslashes is:" 249string(20) ""hello"''world''\0//" 250string(33) "The string after stripslashes is:" 251string(17) ""hello"'world'//" 252 253-- Iteration 27 -- 254string(31) "The string after addslashes is:" 255string(18) "0xABCDEF0123456789" 256string(33) "The string after stripslashes is:" 257string(18) "0xABCDEF0123456789" 258 259-- Iteration 28 -- 260string(31) "The string after addslashes is:" 261string(15) "�cdef0123456789" 262string(33) "The string after stripslashes is:" 263string(15) "�cdef0123456789" 264 265-- Iteration 29 -- 266string(31) "The string after addslashes is:" 267string(18) "!@#$%&*@$%#&/;:,<>" 268string(33) "The string after stripslashes is:" 269string(18) "!@#$%&*@$%#&/;:,<>" 270 271-- Iteration 30 -- 272string(31) "The string after addslashes is:" 273string(12) "hello\0world" 274string(33) "The string after stripslashes is:" 275string(11) "helloworld" 276 277-- Iteration 31 -- 278string(31) "The string after addslashes is:" 279string(71) "This is line 1 of ''heredoc'' string 280This is line 2 of "heredoc" string" 281string(33) "The string after stripslashes is:" 282string(69) "This is line 1 of 'heredoc' string 283This is line 2 of "heredoc" string" 284 285-- Iteration 32 -- 286string(31) "The string after addslashes is:" 287string(0) "" 288string(33) "The string after stripslashes is:" 289string(0) "" 290Done 291