PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/facebook/hiphop-php
PHP | 85 lines | 57 code | 12 blank | 16 comment | 0 complexity | 856f9b9595d2ab181657ff4570eeb616 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?hh
  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. * Test addslashes() with various strings containing characters thats can be backslashed
  8. */
  9. <<__EntryPoint>> function main(): void {
  10. echo "*** Testing addslashes() : with various strings containing characters to be backslashed ***\n";
  11. // initialising a heredoc string
  12. $heredoc_string = <<<EOT
  13. This is line 1 of 'heredoc' string
  14. This is line 2 of "heredoc" string
  15. EOT;
  16. $heredoc_null_string =<<<EOT
  17. EOT;
  18. // initialising the string array
  19. $str_array = varray[
  20. // string without any characters that can be backslashed
  21. 'Hello world',
  22. // string with single quotes
  23. "how're you doing?",
  24. "don't disturb u'r neighbours",
  25. "don't disturb u'r neighbours''",
  26. '',
  27. '\'',
  28. "'",
  29. // string with double quotes
  30. 'he said, "he will be on leave"',
  31. 'he said, ""he will be on leave"',
  32. '"""PHP"""',
  33. "",
  34. "\"",
  35. '"',
  36. "hello\"",
  37. // string with backslash characters
  38. 'Is your name Ram\Krishna?',
  39. '\\0.0.0.0',
  40. 'c:\php\testcase\addslashes',
  41. '\\',
  42. // string with nul characters
  43. 'hello'.chr(0).'world',
  44. chr(0).'hello'.chr(0),
  45. chr(0).chr(0).'hello',
  46. chr(0),
  47. // mixed strings
  48. "'\\0.0.0.0'",
  49. "'\\0.0.0.0'".chr(0),
  50. chr(0)."'c:\php\'",
  51. '"\\0.0.0.0"',
  52. '"c:\php\"'.chr(0)."'",
  53. '"hello"'."'world'".chr(0).'//',
  54. // string with hexadecimal number
  55. "0xABCDEF0123456789",
  56. "\x00",
  57. '!@#$%&*@$%#&/;:,<>',
  58. "hello\x00world",
  59. // heredoc strings
  60. $heredoc_string,
  61. $heredoc_null_string
  62. ];
  63. $count = 1;
  64. // looping to test for all strings in $str_array
  65. foreach( $str_array as $str ) {
  66. echo "\n-- Iteration $count --\n";
  67. var_dump( addslashes($str) );
  68. $count ++;
  69. }
  70. echo "Done\n";
  71. }