PageRenderTime 60ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

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

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