File: stripslashes_basic.phpt

package info (click to toggle)
php8.4 8.4.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 208,108 kB
  • sloc: ansic: 1,060,628; php: 35,345; sh: 11,866; cpp: 7,201; pascal: 4,913; javascript: 3,091; asm: 2,810; yacc: 2,411; makefile: 689; xml: 446; python: 301; awk: 148
file content (53 lines) | stat: -rw-r--r-- 1,899 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
--TEST--
Test stripslashes() function : basic functionality
--FILE--
<?php
/*
 * Testing stripslashes() with quoted strings
*/

echo "*** Testing stripslashes() : basic functionality ***\n";

// Initialize all required variables
$str_array = array( "How's everybody",   // string containing single quote
                    'Are you "JOHN"?',   // string with double quotes
                    'c:\php\stripslashes',   // string with backslashes
                    'c:\\php\\stripslashes',   // string with double backslashes
                    "hello\0world"   // string with nul character
                  );

// Calling striplashes() with all arguments
foreach( $str_array as $str )  {
  $str_addslashes = addslashes($str);
  var_dump("The string after addslashes is:", $str_addslashes);
  $str_stripslashes = stripslashes($str_addslashes);
  var_dump("The string after stripslashes is:", $str_stripslashes);
  if( strcmp($str, $str_stripslashes) != 0 )
    echo "\nError: Original string and string after stripslashes donot match\n";
}

echo "Done\n";
?>
--EXPECTF--
*** Testing stripslashes() : basic functionality ***
string(31) "The string after addslashes is:"
string(16) "How\'s everybody"
string(33) "The string after stripslashes is:"
string(15) "How's everybody"
string(31) "The string after addslashes is:"
string(17) "Are you \"JOHN\"?"
string(33) "The string after stripslashes is:"
string(15) "Are you "JOHN"?"
string(31) "The string after addslashes is:"
string(21) "c:\\php\\stripslashes"
string(33) "The string after stripslashes is:"
string(19) "c:\php\stripslashes"
string(31) "The string after addslashes is:"
string(21) "c:\\php\\stripslashes"
string(33) "The string after stripslashes is:"
string(19) "c:\php\stripslashes"
string(31) "The string after addslashes is:"
string(12) "hello\0world"
string(33) "The string after stripslashes is:"
string(11) "hello%0world"
Done