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