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