explode_variation5.phpt 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. --TEST--
  2. Test explode() function : usage variations - positive and negative limits
  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: positive and negative limits ***\n";
  10. $str = 'one||two||three||four';
  11. echo "\n-- positive limit --\n";
  12. var_dump(explode('||', $str, 2));
  13. echo "\n-- negative limit (since PHP 5.1) --\n";
  14. var_dump(explode('||', $str, -1));
  15. echo "\n-- negative limit (since PHP 5.1) with null string -- \n";
  16. var_dump(explode('||', "", -1));
  17. ?>
  18. ===DONE===
  19. --EXPECT--
  20. *** Testing explode() function: positive and negative limits ***
  21. -- positive limit --
  22. array(2) {
  23. [0]=>
  24. string(3) "one"
  25. [1]=>
  26. string(16) "two||three||four"
  27. }
  28. -- negative limit (since PHP 5.1) --
  29. array(3) {
  30. [0]=>
  31. string(3) "one"
  32. [1]=>
  33. string(3) "two"
  34. [2]=>
  35. string(5) "three"
  36. }
  37. -- negative limit (since PHP 5.1) with null string --
  38. array(0) {
  39. }
  40. ===DONE===