1--TEST--
2Test chunk_split() function : usage variations - different heredoc strings as 'str' argument
3--FILE--
4<?php
5/* Prototype  : string chunk_split(string $str [, int $chunklen [, string $ending]])
6 * Description: Returns split line
7 * Source code: ext/standard/string.c
8 * Alias to functions: none
9*/
10
11/*
12* Passing different heredoc strings as 'str' argument to the chunk_split()
13* with 'chunklen' 4 and default value of 'ending' that is "\r\n"
14*/
15
16echo "*** Testing chunk_split() : heredoc strings as 'str' argument ***\n";
17
18// Initializing required variables
19$chunklen = 4;
20
21// Null heredoc string
22$heredoc_null = <<<EOT1
23EOT1;
24
25// heredoc string with single character
26$heredoc_char = <<<EOT2
27a
28EOT2;
29
30// simple heredoc string
31$heredoc_str = <<<EOT3
32This is simple heredoc string
33EOT3;
34
35// heredoc with special characters
36$heredoc_spchar = <<<EOT4
37This checks heredoc with $, %, &, chars
38EOT4;
39
40// blank heredoc string
41$heredoc_blank = <<<EOT5
42
43EOT5;
44
45// heredoc with different white space characters
46$heredoc_escchar = <<<EOT6
47This checks\t chunk_split()\nEscape\rchars
48EOT6;
49
50// heredoc with multiline
51$heredoc_multiline= <<<EOT7
52This is to check chunk_split
53function with multiline
54heredoc
55EOT7;
56
57// heredoc with quotes and slashes
58$heredoc_quote_slash = <<<EOT8
59"To check " in heredoc"
60I'm sure it'll work also with \
61which is single slash
62EOT8;
63
64//different heredoc strings for 'str'
65$heredoc_arr = array(
66  $heredoc_null,
67  $heredoc_blank,
68  $heredoc_char,
69  $heredoc_str,
70  $heredoc_multiline,
71  $heredoc_spchar,
72  $heredoc_escchar,
73  $heredoc_quote_slash
74);
75
76
77// loop through each element of the heredoc_arr for 'str'
78$count = 0;
79foreach($heredoc_arr as $str) {
80  echo "-- Iteration ".($count+1). " --\n";
81  var_dump( chunk_split( $str, $chunklen) );
82  $count++;
83};
84
85echo "Done"
86?>
87--EXPECTF--
88*** Testing chunk_split() : heredoc strings as 'str' argument ***
89-- Iteration 1 --
90string(2) "
91"
92-- Iteration 2 --
93string(2) "
94"
95-- Iteration 3 --
96string(3) "a
97"
98-- Iteration 4 --
99string(45) "This
100 is
101simp
102le h
103ered
104oc s
105trin
106g
107"
108-- Iteration 5 --
109string(90) "This
110 is
111to c
112heck
113 chu
114nk_s
115plit
116
117fun
118ctio
119n wi
120th m
121ulti
122line
123
124her
125edoc
126"
127-- Iteration 6 --
128string(59) "This
129 che
130cks
131here
132doc
133with
134 $,
135%, &
136, ch
137ars
138"
139-- Iteration 7 --
140string(59) "This
141 che
142cks
143 chu
144nk_s
145plit
146()
147E
148scap
149e
149ch
150ars
151"
152-- Iteration 8 --
153string(117) ""To
154chec
155k "
156in h
157ered
158oc"
159
160I'm
161sure
162 it'
163ll w
164ork
165also
166 wit
167h \
168
169whic
170h is
171 sin
172gle
173slas
174h
175"
176Done
177