PageRenderTime 14ms CodeModel.GetById 22ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/hphp/test/zend/good/ext/standard/tests/strings/addslashes_variation2.php

https://github.com/betashepherd/hhvm
PHP | 85 lines | 56 code | 13 blank | 16 comment | 0 complexity | bf609855d1a16bb9ab6d95c47c48aa90 MD5 | raw file
 1<?php
 2/* Prototype  : string addslashes ( string $str )
 3 * Description: Returns a string with backslashes before characters that need to be quoted in database queries etc.
 4 * Source code: ext/standard/string.c
 5*/
 6
 7/*
 8 * Test addslashes() with various strings containing characters thats can be backslashed 
 9*/
10
11echo "*** Testing addslashes() : with various strings containing characters to be backslashed ***\n";
12
13// initialising a heredoc string
14$heredoc_string = <<<EOT
15This is line 1 of 'heredoc' string
16This is line 2 of "heredoc" string
17EOT;
18
19$heredoc_null_string =<<<EOT
20EOT;
21 
22// initialising the string array
23
24$str_array = array( 
25                    // string without any characters that can be backslashed
26                    'Hello world',
27 
28                    // string with single quotes
29                    "how're you doing?", 
30                    "don't disturb u'r neighbours",
31                    "don't disturb u'r neighbours''",
32                    '',
33                    '\'',
34                    "'",
35                    
36                    // string with double quotes
37                    'he said, "he will be on leave"',
38                    'he said, ""he will be on leave"',
39                    '"""PHP"""',
40                    "",
41                    "\"",
42                    '"',
43 		    "hello\"",
44                         
45                    // string with backslash characters
46                    'Is your name Ram\Krishna?',
47                    '\\0.0.0.0',
48                    'c:\php\testcase\addslashes',
49                    '\\',
50
51                    // string with nul characters
52                    'hello'.chr(0).'world',
53                    chr(0).'hello'.chr(0),
54                    chr(0).chr(0).'hello',
55                    chr(0),
56
57                    // mixed strings
58                    "'\\0.0.0.0'",
59                    "'\\0.0.0.0'".chr(0),
60                    chr(0)."'c:\php\'",
61                    '"\\0.0.0.0"',
62                    '"c:\php\"'.chr(0)."'",
63                    '"hello"'."'world'".chr(0).'//',
64
65		    // string with hexadecimal number
66                    "0xABCDEF0123456789",
67                    "\x00",
68                    '!@#$%&*@$%#&/;:,<>',
69                    "hello\x00world",
70
71                    // heredoc strings
72                    $heredoc_string,
73                    $heredoc_null_string
74                  );
75
76$count = 1;
77// looping to test for all strings in $str_array
78foreach( $str_array as $str )  {
79  echo "\n-- Iteration $count --\n";
80  var_dump( addslashes($str) );
81  $count ++;
82}
83
84echo "Done\n";
85?>