PageRenderTime 43ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

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

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