PageRenderTime 51ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

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

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