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(0) { 85} 86-- Iteration 2 -- 87array(0) { 88} 89-- Iteration 3 -- 90array(1) { 91 [0]=> 92 string(1) "a" 93} 94-- Iteration 4 -- 95array(3) { 96 [0]=> 97 string(10) "This is si" 98 [1]=> 99 string(10) "mple hered" 100 [2]=> 101 string(9) "oc string" 102} 103-- Iteration 5 -- 104array(6) { 105 [0]=> 106 string(10) "This is to" 107 [1]=> 108 string(10) " check str" 109 [2]=> 110 string(10) "_split 111fun" 112 [3]=> 113 string(10) "ction with" 114 [4]=> 115 string(10) " multiline" 116 [5]=> 117 string(8) " 118heredoc" 119} 120-- Iteration 6 -- 121array(4) { 122 [0]=> 123 string(10) "This check" 124 [1]=> 125 string(10) "s heredoc " 126 [2]=> 127 string(10) "with $, %," 128 [3]=> 129 string(9) " &, chars" 130} 131-- Iteration 7 -- 132array(4) { 133 [0]=> 134 string(10) "This check" 135 [1]=> 136 string(10) "s str_spl" 137 [2]=> 138 string(10) "it() 139Escap" 140 [3]=> 141 string(7) "e 141chars" 142} 143-- Iteration 8 -- 144array(8) { 145 [0]=> 146 string(10) ""To check " 147 [1]=> 148 string(10) "" in hered" 149 [2]=> 150 string(10) "oc" 151I'm su" 152 [3]=> 153 string(10) "re it'll w" 154 [4]=> 155 string(10) "ork also w" 156 [5]=> 157 string(10) "ith \ 158whic" 159 [6]=> 160 string(10) "h is singl" 161 [7]=> 162 string(7) "e slash" 163} 164Done 165