addslashes_basic.phpt 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. --TEST--
  2. Test addslashes() function : basic functionality
  3. --FILE--
  4. <?php
  5. /* Prototype : string addslashes ( string $str )
  6. * Description: Returns a string with backslashes before characters (single quotes, double quote,
  7. * backslash and nul character) that need to be quoted in database queries etc.
  8. * Source code: ext/standard/string.c
  9. */
  10. /*
  11. * Testing addslashes() with strings containing characters that can be prefixed with backslash
  12. * by the function
  13. */
  14. echo "*** Testing addslashes() : basic functionality ***\n";
  15. // Initialize all required variables
  16. $str_array = array( "How's everybody", // string containing single quote
  17. 'Are you "JOHN"?', // string with double quotes
  18. 'c:\php\addslashes', // string with backslashes
  19. "hello\0world" // string with nul character
  20. );
  21. // Calling addslashes() with all arguments
  22. foreach( $str_array as $str ) {
  23. var_dump( addslashes($str) );
  24. }
  25. echo "Done\n";
  26. ?>
  27. --EXPECTF--
  28. *** Testing addslashes() : basic functionality ***
  29. string(16) "How\'s everybody"
  30. string(17) "Are you \"JOHN\"?"
  31. string(19) "c:\\php\\addslashes"
  32. string(12) "hello\0world"
  33. Done