PageRenderTime 35ms CodeModel.GetById 7ms RepoModel.GetById 1ms app.codeStats 0ms

/php5/ext/standard/tests/strings/addslashes_variation2.phpt

http://github.com/vpj/PHP-Extension-API
Unknown | 195 lines | 146 code | 49 blank | 0 comment | 0 complexity | 99c8829b6cdf276360a8b0a21d88369f MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-2.1, BSD-3-Clause
  1. --TEST--
  2. Test addslashes() function : usage variations - strings with characters to be backslashed
  3. --INI--
  4. --FILE--
  5. <?php
  6. /* Prototype : string addslashes ( string $str )
  7. * Description: Returns a string with backslashes before characters that need to be quoted in database queries etc.
  8. * Source code: ext/standard/string.c
  9. */
  10. /*
  11. * Test addslashes() with various strings containing characters thats can be backslashed
  12. */
  13. echo "*** Testing addslashes() : with various strings containing characters to be backslashed ***\n";
  14. // initialising a heredoc string
  15. $heredoc_string = <<<EOT
  16. This is line 1 of 'heredoc' string
  17. This is line 2 of "heredoc" string
  18. EOT;
  19. $heredoc_null_string =<<<EOT
  20. EOT;
  21. // initialising the string array
  22. $str_array = array(
  23. // string without any characters that can be backslashed
  24. 'Hello world',
  25. // string with single quotes
  26. "how're you doing?",
  27. "don't disturb u'r neighbours",
  28. "don't disturb u'r neighbours''",
  29. '',
  30. '\'',
  31. "'",
  32. // string with double quotes
  33. 'he said, "he will be on leave"',
  34. 'he said, ""he will be on leave"',
  35. '"""PHP"""',
  36. "",
  37. "\"",
  38. '"',
  39. "hello\"",
  40. // string with backslash characters
  41. 'Is your name Ram\Krishna?',
  42. '\\0.0.0.0',
  43. 'c:\php\testcase\addslashes',
  44. '\\',
  45. // string with nul characters
  46. 'hello'.chr(0).'world',
  47. chr(0).'hello'.chr(0),
  48. chr(0).chr(0).'hello',
  49. chr(0),
  50. // mixed strings
  51. "'\\0.0.0.0'",
  52. "'\\0.0.0.0'".chr(0),
  53. chr(0)."'c:\php\'",
  54. '"\\0.0.0.0"',
  55. '"c:\php\"'.chr(0)."'",
  56. '"hello"'."'world'".chr(0).'//',
  57. // string with hexadecimal number
  58. "0xABCDEF0123456789",
  59. "\x00",
  60. '!@#$%&*@$%#&/;:,<>',
  61. "hello\x00world",
  62. // heredoc strings
  63. $heredoc_string,
  64. $heredoc_null_string
  65. );
  66. $count = 1;
  67. // looping to test for all strings in $str_array
  68. foreach( $str_array as $str ) {
  69. echo "\n-- Iteration $count --\n";
  70. var_dump( addslashes($str) );
  71. $count ++;
  72. }
  73. echo "Done\n";
  74. ?>
  75. --EXPECTF--
  76. *** Testing addslashes() : with various strings containing characters to be backslashed ***
  77. -- Iteration 1 --
  78. string(11) "Hello world"
  79. -- Iteration 2 --
  80. string(18) "how\'re you doing?"
  81. -- Iteration 3 --
  82. string(30) "don\'t disturb u\'r neighbours"
  83. -- Iteration 4 --
  84. string(34) "don\'t disturb u\'r neighbours\'\'"
  85. -- Iteration 5 --
  86. string(0) ""
  87. -- Iteration 6 --
  88. string(2) "\'"
  89. -- Iteration 7 --
  90. string(2) "\'"
  91. -- Iteration 8 --
  92. string(32) "he said, \"he will be on leave\""
  93. -- Iteration 9 --
  94. string(34) "he said, \"\"he will be on leave\""
  95. -- Iteration 10 --
  96. string(15) "\"\"\"PHP\"\"\""
  97. -- Iteration 11 --
  98. string(0) ""
  99. -- Iteration 12 --
  100. string(2) "\""
  101. -- Iteration 13 --
  102. string(2) "\""
  103. -- Iteration 14 --
  104. string(7) "hello\""
  105. -- Iteration 15 --
  106. string(26) "Is your name Ram\\Krishna?"
  107. -- Iteration 16 --
  108. string(9) "\\0.0.0.0"
  109. -- Iteration 17 --
  110. string(29) "c:\\php\\testcase\\addslashes"
  111. -- Iteration 18 --
  112. string(2) "\\"
  113. -- Iteration 19 --
  114. string(12) "hello\0world"
  115. -- Iteration 20 --
  116. string(9) "\0hello\0"
  117. -- Iteration 21 --
  118. string(9) "\0\0hello"
  119. -- Iteration 22 --
  120. string(2) "\0"
  121. -- Iteration 23 --
  122. string(13) "\'\\0.0.0.0\'"
  123. -- Iteration 24 --
  124. string(15) "\'\\0.0.0.0\'\0"
  125. -- Iteration 25 --
  126. string(15) "\0\'c:\\php\\\'"
  127. -- Iteration 26 --
  128. string(13) "\"\\0.0.0.0\""
  129. -- Iteration 27 --
  130. string(17) "\"c:\\php\\\"\0\'"
  131. -- Iteration 28 --
  132. string(22) "\"hello\"\'world\'\0//"
  133. -- Iteration 29 --
  134. string(18) "0xABCDEF0123456789"
  135. -- Iteration 30 --
  136. string(2) "\0"
  137. -- Iteration 31 --
  138. string(18) "!@#$%&*@$%#&/;:,<>"
  139. -- Iteration 32 --
  140. string(12) "hello\0world"
  141. -- Iteration 33 --
  142. string(73) "This is line 1 of \'heredoc\' string
  143. This is line 2 of \"heredoc\" string"
  144. -- Iteration 34 --
  145. string(0) ""
  146. Done