explode_variation6.phpt 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. --TEST--
  2. Test explode() function : usage variations - misc tests
  3. --FILE--
  4. <?php
  5. /* Prototype : array explode ( string $delimiter , string $string [, int $limit ] )
  6. * Description: Split a string by string.
  7. * Source code: ext/standard/string.c
  8. */
  9. echo "*** Testing explode() function: misc tests ***\n";
  10. $str = "one\x00two\x00three\x00four";
  11. echo "\n-- positive limit with null separator --\n";
  12. $e = test_explode("\x00", $str, 2);
  13. echo "\n-- negative limit (since PHP 5.1) with null separator --\n";
  14. $e = test_explode("\x00", $str, -2);
  15. echo "\n-- unknown string --\n";
  16. $e = test_explode("fred", $str,1);
  17. echo "\n-- limit = 0 --\n";
  18. $e = test_explode("\x00", $str, 0);
  19. echo "\n-- limit = -1 --\n";
  20. $e = test_explode("\x00", $str, -1);
  21. echo "\n-- large limit = -100 --\n";
  22. $e = test_explode("\x00", $str, 100);
  23. function test_explode($delim, $string, $limit)
  24. {
  25. $e = explode($delim, $string, $limit);
  26. foreach ( $e as $v)
  27. {
  28. var_dump(bin2hex($v));
  29. }
  30. }
  31. ?>
  32. ===DONE===
  33. --EXPECT--
  34. *** Testing explode() function: misc tests ***
  35. -- positive limit with null separator --
  36. string(6) "6f6e65"
  37. string(28) "74776f00746872656500666f7572"
  38. -- negative limit (since PHP 5.1) with null separator --
  39. string(6) "6f6e65"
  40. string(6) "74776f"
  41. -- unknown string --
  42. string(36) "6f6e650074776f00746872656500666f7572"
  43. -- limit = 0 --
  44. string(36) "6f6e650074776f00746872656500666f7572"
  45. -- limit = -1 --
  46. string(6) "6f6e65"
  47. string(6) "74776f"
  48. string(10) "7468726565"
  49. -- large limit = -100 --
  50. string(6) "6f6e65"
  51. string(6) "74776f"
  52. string(10) "7468726565"
  53. string(8) "666f7572"
  54. ===DONE===