1--TEST--
2Test str_split() function : usage variations - different heredoc strings as 'str' argument
3--FILE--
4<?php
5/*
6* Passing different heredoc strings as 'str' argument to the str_split()
7* with 'split_length' 10
8*/
9
10echo "*** Testing str_split() : heredoc strings as 'str' argument ***\n";
11
12// Initializing required variables
13$split_length = 10;
14
15// Null heredoc string
16$heredoc_null = <<<EOT1
17EOT1;
18
19// heredoc string with single character
20$heredoc_char = <<<EOT2
21a
22EOT2;
23
24// simple heredoc string
25$heredoc_str = <<<EOT3
26This is simple heredoc string
27EOT3;
28
29// heredoc with special characters
30$heredoc_spchar = <<<EOT4
31This checks heredoc with $, %, &, chars
32EOT4;
33
34// blank heredoc string
35$heredoc_blank = <<<EOT5
36
37EOT5;
38
39// heredoc with different white space characters
40$heredoc_escchar = <<<EOT6
41This checks\t str_split()\nEscape\rchars
42EOT6;
43
44// heredoc with multiline
45$heredoc_multiline= <<<EOT7
46This is to check str_split
47function with multiline
48heredoc
49EOT7;
50
51// heredoc with quotes and slashes
52$heredoc_quote_slash = <<<EOT8
53"To check " in heredoc"
54I'm sure it'll work also with \
55which is single slash
56EOT8;
57
58//different heredoc strings for 'str'
59$heredoc_array = array(
60  $heredoc_null,
61  $heredoc_blank,
62  $heredoc_char,
63  $heredoc_str,
64  $heredoc_multiline,
65  $heredoc_spchar,
66  $heredoc_escchar,
67  $heredoc_quote_slash
68);
69
70
71// loop through each element of the 'heredoc_array' for 'str'
72$count = 0;
73foreach($heredoc_array as $str) {
74  echo "-- Iteration ".($count+1). " --\n";
75  var_dump( str_split($str, $split_length) );
76  $count++;
77};
78
79echo "Done"
80?>
81--EXPECT--
82*** Testing str_split() : heredoc strings as 'str' argument ***
83-- Iteration 1 --
84array(1) {
85  [0]=>
86  string(0) ""
87}
88-- Iteration 2 --
89array(1) {
90  [0]=>
91  string(0) ""
92}
93-- Iteration 3 --
94array(1) {
95  [0]=>
96  string(1) "a"
97}
98-- Iteration 4 --
99array(3) {
100  [0]=>
101  string(10) "This is si"
102  [1]=>
103  string(10) "mple hered"
104  [2]=>
105  string(9) "oc string"
106}
107-- Iteration 5 --
108array(6) {
109  [0]=>
110  string(10) "This is to"
111  [1]=>
112  string(10) " check str"
113  [2]=>
114  string(10) "_split
115fun"
116  [3]=>
117  string(10) "ction with"
118  [4]=>
119  string(10) " multiline"
120  [5]=>
121  string(8) "
122heredoc"
123}
124-- Iteration 6 --
125array(4) {
126  [0]=>
127  string(10) "This check"
128  [1]=>
129  string(10) "s heredoc "
130  [2]=>
131  string(10) "with $, %,"
132  [3]=>
133  string(9) " &, chars"
134}
135-- Iteration 7 --
136array(4) {
137  [0]=>
138  string(10) "This check"
139  [1]=>
140  string(10) "s	 str_spl"
141  [2]=>
142  string(10) "it()
143Escap"
144  [3]=>
145  string(7) "e
145chars"
146}
147-- Iteration 8 --
148array(8) {
149  [0]=>
150  string(10) ""To check "
151  [1]=>
152  string(10) "" in hered"
153  [2]=>
154  string(10) "oc"
155I'm su"
156  [3]=>
157  string(10) "re it'll w"
158  [4]=>
159  string(10) "ork also w"
160  [5]=>
161  string(10) "ith \
162whic"
163  [6]=>
164  string(10) "h is singl"
165  [7]=>
166  string(7) "e slash"
167}
168Done
169