PageRenderTime 48ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://github.com/chalos/hhvm
PHP | 103 lines | 86 code | 6 blank | 11 comment | 0 complexity | 63cb4d35b1521c2f1eab672a57c2a0ff 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 stripslashes ( string $str )
  3. * Description: Returns an un-quoted string
  4. * Source code: ext/standard/string.c
  5. */
  6. /*
  7. * Test stripslashes() with various strings containing characters thats can be backslashed.
  8. * First adding slashes using addslashes() and then removing the slashes using stripslashes()
  9. */
  10. echo "*** Testing stripslashes() : with various strings containing backslashed characters ***\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. $heredoc_string_only_backslash =<<<EOT
  19. \
  20. EOT;
  21. $heredoc_string_only_single_quote =<<<EOT
  22. '
  23. EOT;
  24. $heredoc_string_only_double_quote =<<<EOT
  25. "
  26. EOT;
  27. // initialising the string array
  28. $str_array = array(
  29. // string without any characters that can be backslashed
  30. 'Hello world',
  31. // string with single quotes
  32. "how're you doing?",
  33. "don't disturb u'r neighbours",
  34. "don't disturb u'r neighbours''",
  35. '',
  36. '\'',
  37. "'",
  38. $heredoc_string_only_single_quote,
  39. // string with double quotes
  40. 'he said, "he will be on leave"',
  41. 'he said, ""he will be on leave"',
  42. '"""PHP"""',
  43. "",
  44. "\"",
  45. '"',
  46. "hello\"",
  47. $heredoc_string_only_double_quote,
  48. // string with backslash characters
  49. 'Is your name Ram\Krishna?',
  50. '\\0.0.0.0',
  51. 'c:\php\testcase\stripslashes',
  52. '\\',
  53. $heredoc_string_only_backslash,
  54. // string with nul characters
  55. 'hello'.chr(0).'world',
  56. chr(0).'hello'.chr(0),
  57. chr(0).chr(0).'hello',
  58. chr(0),
  59. // mixed strings
  60. "'\\0.0.0.0'",
  61. "'\\0.0.0.0'".chr(0),
  62. chr(0)."'c:\php\'",
  63. '"\\0.0.0.0"',
  64. '"c:\php\"'.chr(0)."'",
  65. '"hello"'."'world'".chr(0).'//',
  66. // string with hexadecimal number
  67. "0xABCDEF0123456789",
  68. "\x00",
  69. '!@#$%&*@$%#&/;:,<>',
  70. "hello\x00world",
  71. // heredoc strings
  72. $heredoc_string,
  73. $heredoc_null_string
  74. );
  75. $count = 1;
  76. // looping to test for all strings in $str_array
  77. foreach( $str_array as $str ) {
  78. echo "\n-- Iteration $count --\n";
  79. $str_addslashes = addslashes($str);
  80. var_dump("The string after addslashes is:", $str_addslashes);
  81. $str_stripslashes = stripslashes($str_addslashes);
  82. var_dump("The string after stripslashes is:", $str_stripslashes);
  83. if( strcmp($str, $str_stripslashes) != 0 )
  84. echo "\nError: Original string and string from stripslash() donot match\n";
  85. $count ++;
  86. }
  87. echo "Done\n";
  88. ?>