str_split_basic.phpt 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. --TEST--
  2. Test str_split() function : basic functionality
  3. --FILE--
  4. <?php
  5. /* Prototype : array str_split(string $str [, int $split_length])
  6. * Description: Convert a string to an array. If split_length is
  7. specified, break the string down into chunks each
  8. split_length characters long.
  9. * Source code: ext/standard/string.c
  10. * Alias to functions: none
  11. */
  12. echo "*** Testing str_split() : basic functionality ***\n";
  13. // Initialise all required variables
  14. $str = 'This is basic testcase';
  15. $split_length = 5;
  16. // Calling str_split() with all possible arguments
  17. echo "-- With all possible arguments --\n";
  18. var_dump( str_split($str,$split_length) );
  19. // Calling str_split() with default arguments
  20. echo "-- With split_length as default argument --\n";
  21. var_dump( str_split($str) );
  22. echo "Done"
  23. ?>
  24. --EXPECTF--
  25. *** Testing str_split() : basic functionality ***
  26. -- With all possible arguments --
  27. array(5) {
  28. [0]=>
  29. string(5) "This "
  30. [1]=>
  31. string(5) "is ba"
  32. [2]=>
  33. string(5) "sic t"
  34. [3]=>
  35. string(5) "estca"
  36. [4]=>
  37. string(2) "se"
  38. }
  39. -- With split_length as default argument --
  40. array(22) {
  41. [0]=>
  42. string(1) "T"
  43. [1]=>
  44. string(1) "h"
  45. [2]=>
  46. string(1) "i"
  47. [3]=>
  48. string(1) "s"
  49. [4]=>
  50. string(1) " "
  51. [5]=>
  52. string(1) "i"
  53. [6]=>
  54. string(1) "s"
  55. [7]=>
  56. string(1) " "
  57. [8]=>
  58. string(1) "b"
  59. [9]=>
  60. string(1) "a"
  61. [10]=>
  62. string(1) "s"
  63. [11]=>
  64. string(1) "i"
  65. [12]=>
  66. string(1) "c"
  67. [13]=>
  68. string(1) " "
  69. [14]=>
  70. string(1) "t"
  71. [15]=>
  72. string(1) "e"
  73. [16]=>
  74. string(1) "s"
  75. [17]=>
  76. string(1) "t"
  77. [18]=>
  78. string(1) "c"
  79. [19]=>
  80. string(1) "a"
  81. [20]=>
  82. string(1) "s"
  83. [21]=>
  84. string(1) "e"
  85. }
  86. Done