trim_basic.phpt 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. --TEST--
  2. Test trim() function : basic functionality
  3. --FILE--
  4. <?php
  5. /* Prototype : string trim ( string $str [, string $charlist ] )
  6. * Description: Strip whitespace (or other characters) from the beginning and end of a string.
  7. * Source code: ext/standard/string.c
  8. */
  9. echo "*** Testing trim() : basic functionality ***\n";
  10. $text = " \t\r\n\0\x0B ---These are a few words--- \t\r\n\0\x0B ";
  11. $hello = "!===Hello World===!";
  12. $binary = "\x0A\x0DExample string\x0A\x0D";
  13. echo "\n-- Trim string with all white space characters --\n";
  14. var_dump(trim($text));
  15. echo "\n-- Trim non-whitespace from a string --\n";
  16. var_dump(trim($hello, "=!"));
  17. echo "\n-- Trim some non-white space characters from a string --\n";
  18. var_dump(trim($hello, "Hdle"));
  19. echo "\n-- Trim the ASCII control characters at the beginning of a string --\n";
  20. var_dump(trim($binary, "\x00..\x1F"));
  21. ?>
  22. ===DONE===
  23. --EXPECT--
  24. *** Testing trim() : basic functionality ***
  25. -- Trim string with all white space characters --
  26. string(27) "---These are a few words---"
  27. -- Trim non-whitespace from a string --
  28. string(11) "Hello World"
  29. -- Trim some non-white space characters from a string --
  30. string(19) "!===Hello World===!"
  31. -- Trim the ASCII control characters at the beginning of a string --
  32. string(14) "Example string"
  33. ===DONE===