1--TEST--
2Test str_split() function : usage variations - different double quoted strings for 'str' argument
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
13/*
14* passing different double quoted strings as 'str' argument to str_split()
15* split_length is set to 7
16*/
17
18echo "*** Testing str_split() : double quoted strings for 'str' ***\n";
19
20//Initialize variables
21$split_length = 7;
22
23// different values for 'str'
24$values = array(
25  "",  //empty
26  " ",  //space
27  "1234", //with only numbers
28  "simple string",  //regular string
29  "It's string with quote",  //string containing single quote
30  "string\tcontains\rwhite space\nchars",
31  "containing @ # $ % ^ & chars",
32  "with 1234 numbers",
33  "with \0 and ".chr(0)."null chars",  //for binary safe
34  "with    multiple     space char",
35  "Testing invalid \k and \m escape char",
36  "to check with \\n and \\t" //ignoring \n and \t results
37
38);
39
40//loop through each element of $values for 'str' argument
41for($count = 0; $count < count($values); $count++) {
42  echo "-- Iteration ".($count+1)." --\n";
43  var_dump( str_split($values[$count], $split_length) );
44}
45echo "Done"
46?>
47--EXPECTF--
48*** Testing str_split() : double quoted strings for 'str' ***
49-- Iteration 1 --
50array(1) {
51  [0]=>
52  string(0) ""
53}
54-- Iteration 2 --
55array(1) {
56  [0]=>
57  string(1) " "
58}
59-- Iteration 3 --
60array(1) {
61  [0]=>
62  string(4) "1234"
63}
64-- Iteration 4 --
65array(2) {
66  [0]=>
67  string(7) "simple "
68  [1]=>
69  string(6) "string"
70}
71-- Iteration 5 --
72array(4) {
73  [0]=>
74  string(7) "It's st"
75  [1]=>
76  string(7) "ring wi"
77  [2]=>
78  string(7) "th quot"
79  [3]=>
80  string(1) "e"
81}
82-- Iteration 6 --
83array(5) {
84  [0]=>
85  string(7) "string	"
86  [1]=>
87  string(7) "contain"
88  [2]=>
89  string(7) "s
89white"
90  [3]=>
91  string(7) " space
92"
93  [4]=>
94  string(5) "chars"
95}
96-- Iteration 7 --
97array(4) {
98  [0]=>
99  string(7) "contain"
100  [1]=>
101  string(7) "ing @ #"
102  [2]=>
103  string(7) " $ % ^ "
104  [3]=>
105  string(7) "& chars"
106}
107-- Iteration 8 --
108array(3) {
109  [0]=>
110  string(7) "with 12"
111  [1]=>
112  string(7) "34 numb"
113  [2]=>
114  string(3) "ers"
115}
116-- Iteration 9 --
117array(4) {
118  [0]=>
119  string(7) "with � "
120  [1]=>
121  string(7) "and �nu"
122  [2]=>
123  string(7) "ll char"
124  [3]=>
125  string(1) "s"
126}
127-- Iteration 10 --
128array(5) {
129  [0]=>
130  string(7) "with   "
131  [1]=>
132  string(7) " multip"
133  [2]=>
134  string(7) "le     "
135  [3]=>
136  string(7) "space c"
137  [4]=>
138  string(3) "har"
139}
140-- Iteration 11 --
141array(6) {
142  [0]=>
143  string(7) "Testing"
144  [1]=>
145  string(7) " invali"
146  [2]=>
147  string(7) "d \k an"
148  [3]=>
149  string(7) "d \m es"
150  [4]=>
151  string(7) "cape ch"
152  [5]=>
153  string(2) "ar"
154}
155-- Iteration 12 --
156array(4) {
157  [0]=>
158  string(7) "to chec"
159  [1]=>
160  string(7) "k with "
161  [2]=>
162  string(7) "\n and "
163  [3]=>
164  string(2) "\t"
165}
166Done
167