explode_variation5.phpt 840 B

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