1--TEST--
2Test str_split() function : usage variations - different single 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 single quoted strings as 'str' argument to str_split()
15* split_length is set to 5
16*/
17
18echo "*** Testing str_split() : single quoted strings for 'str' ***\n";
19
20//Initialize variables
21$split_length = 5;
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//loop through each element of $values for 'str' argument
40for($count = 0; $count < count($values); $count++) {
41  echo "-- Iteration ".($count+1)." --\n";
42  var_dump( str_split($values[$count], $split_length) );
43}
44echo "Done"
45?>
46--EXPECT--
47*** Testing str_split() : single quoted strings for 'str' ***
48-- Iteration 1 --
49array(1) {
50  [0]=>
51  string(0) ""
52}
53-- Iteration 2 --
54array(1) {
55  [0]=>
56  string(1) " "
57}
58-- Iteration 3 --
59array(1) {
60  [0]=>
61  string(4) "1234"
62}
63-- Iteration 4 --
64array(3) {
65  [0]=>
66  string(5) "simpl"
67  [1]=>
68  string(5) "e str"
69  [2]=>
70  string(3) "ing"
71}
72-- Iteration 5 --
73array(5) {
74  [0]=>
75  string(5) "It's "
76  [1]=>
77  string(5) "strin"
78  [2]=>
79  string(5) "g wit"
80  [3]=>
81  string(5) "h quo"
82  [4]=>
83  string(2) "te"
84}
85-- Iteration 6 --
86array(8) {
87  [0]=>
88  string(5) "strin"
89  [1]=>
90  string(5) "g\tco"
91  [2]=>
92  string(5) "ntain"
93  [3]=>
94  string(5) "s\rwh"
95  [4]=>
96  string(5) "ite s"
97  [5]=>
98  string(5) "pace\"
99  [6]=>
100  string(5) "nchar"
101  [7]=>
102  string(1) "s"
103}
104-- Iteration 7 --
105array(6) {
106  [0]=>
107  string(5) "conta"
108  [1]=>
109  string(5) "ining"
110  [2]=>
111  string(5) " @ # "
112  [3]=>
113  string(5) "$ % ^"
114  [4]=>
115  string(5) " & ch"
116  [5]=>
117  string(3) "ars"
118}
119-- Iteration 8 --
120array(4) {
121  [0]=>
122  string(5) "with "
123  [1]=>
124  string(5) "1234 "
125  [2]=>
126  string(5) "numbe"
127  [3]=>
128  string(2) "rs"
129}
130-- Iteration 9 --
131array(7) {
132  [0]=>
133  string(5) "with "
134  [1]=>
135  string(5) "\0 an"
136  [2]=>
137  string(5) "d ".c"
138  [3]=>
139  string(5) "hr(0)"
140  [4]=>
141  string(5) "."nul"
142  [5]=>
143  string(5) "l cha"
144  [6]=>
145  string(2) "rs"
146}
147-- Iteration 10 --
148array(7) {
149  [0]=>
150  string(5) "with "
151  [1]=>
152  string(5) "   mu"
153  [2]=>
154  string(5) "ltipl"
155  [3]=>
156  string(5) "e    "
157  [4]=>
158  string(5) " spac"
159  [5]=>
160  string(5) "e cha"
161  [6]=>
162  string(1) "r"
163}
164-- Iteration 11 --
165array(8) {
166  [0]=>
167  string(5) "Testi"
168  [1]=>
169  string(5) "ng in"
170  [2]=>
171  string(5) "valid"
172  [3]=>
173  string(5) " \k a"
174  [4]=>
175  string(5) "nd \m"
176  [5]=>
177  string(5) " esca"
178  [6]=>
179  string(5) "pe ch"
180  [7]=>
181  string(2) "ar"
182}
183-- Iteration 12 --
184array(5) {
185  [0]=>
186  string(5) "to ch"
187  [1]=>
188  string(5) "eck w"
189  [2]=>
190  string(5) "ith \"
191  [3]=>
192  string(5) "n and"
193  [4]=>
194  string(3) " \t"
195}
196Done
197