stripslashes_basic.phpt 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. --TEST--
  2. Test stripslashes() function : basic functionality
  3. --FILE--
  4. <?php
  5. /* Prototype : string stripslashes ( string $str )
  6. * Description: Un-quotes a quoted string
  7. * Source code: ext/standard/string.c
  8. */
  9. /*
  10. * Testing stripslashes() with quoted strings
  11. */
  12. echo "*** Testing stripslashes() : basic functionality ***\n";
  13. // Initialize all required variables
  14. $str_array = array( "How's everybody", // string containing single quote
  15. 'Are you "JOHN"?', // string with double quotes
  16. 'c:\php\stripslashes', // string with backslashes
  17. 'c:\\php\\stripslashes', // string with double backslashes
  18. "hello\0world" // string with nul character
  19. );
  20. // Calling striplashes() with all arguments
  21. foreach( $str_array as $str ) {
  22. $str_addslashes = addslashes($str);
  23. var_dump("The string after addslashes is:", $str_addslashes);
  24. $str_stripslashes = stripslashes($str_addslashes);
  25. var_dump("The string after stripslashes is:", $str_stripslashes);
  26. if( strcmp($str, $str_stripslashes) != 0 )
  27. echo "\nError: Original string and string after stripslashes donot match\n";
  28. }
  29. echo "Done\n";
  30. ?>
  31. --EXPECTF--
  32. *** Testing stripslashes() : basic functionality ***
  33. string(31) "The string after addslashes is:"
  34. string(16) "How\'s everybody"
  35. string(33) "The string after stripslashes is:"
  36. string(15) "How's everybody"
  37. string(31) "The string after addslashes is:"
  38. string(17) "Are you \"JOHN\"?"
  39. string(33) "The string after stripslashes is:"
  40. string(15) "Are you "JOHN"?"
  41. string(31) "The string after addslashes is:"
  42. string(21) "c:\\php\\stripslashes"
  43. string(33) "The string after stripslashes is:"
  44. string(19) "c:\php\stripslashes"
  45. string(31) "The string after addslashes is:"
  46. string(21) "c:\\php\\stripslashes"
  47. string(33) "The string after stripslashes is:"
  48. string(19) "c:\php\stripslashes"
  49. string(31) "The string after addslashes is:"
  50. string(12) "hello\0world"
  51. string(33) "The string after stripslashes is:"
  52. string(11) "hello�world"
  53. Done