stripslashes_basic.phpt 1.9 KB

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