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