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