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