1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
--TEST--
Test str_split() function : usage variations - different double quoted strings for 'str' argument
--FILE--
<?php
/*
* passing different double quoted strings as 'str' argument to str_split()
* split_length is set to 7
*/
echo "*** Testing str_split() : double quoted strings for 'str' ***\n";
//Initialize variables
$split_length = 7;
// different values for 'str'
$values = array(
"", //empty
" ", //space
"1234", //with only numbers
"simple string", //regular string
"It's string with quote", //string containing single quote
"string\tcontains\rwhite space\nchars",
"containing @ # $ % ^ & chars",
"with 1234 numbers",
"with \0 and ".chr(0)."null chars", //for binary safe
"with multiple space char",
"Testing invalid \k and \m escape char",
"to check with \\n and \\t" //ignoring \n and \t results
);
//loop through each element of $values for 'str' argument
for($count = 0; $count < count($values); $count++) {
echo "-- Iteration ".($count+1)." --\n";
var_dump( str_split($values[$count], $split_length) );
}
echo "Done"
?>
--EXPECTF--
*** Testing str_split() : double quoted strings for 'str' ***
-- Iteration 1 --
array(0) {
}
-- Iteration 2 --
array(1) {
[0]=>
string(1) " "
}
-- Iteration 3 --
array(1) {
[0]=>
string(4) "1234"
}
-- Iteration 4 --
array(2) {
[0]=>
string(7) "simple "
[1]=>
string(6) "string"
}
-- Iteration 5 --
array(4) {
[0]=>
string(7) "It's st"
[1]=>
string(7) "ring wi"
[2]=>
string(7) "th quot"
[3]=>
string(1) "e"
}
-- Iteration 6 --
array(5) {
[0]=>
string(7) "string "
[1]=>
string(7) "contain"
[2]=>
string(7) "s
white"
[3]=>
string(7) " space
"
[4]=>
string(5) "chars"
}
-- Iteration 7 --
array(4) {
[0]=>
string(7) "contain"
[1]=>
string(7) "ing @ #"
[2]=>
string(7) " $ % ^ "
[3]=>
string(7) "& chars"
}
-- Iteration 8 --
array(3) {
[0]=>
string(7) "with 12"
[1]=>
string(7) "34 numb"
[2]=>
string(3) "ers"
}
-- Iteration 9 --
array(4) {
[0]=>
string(7) "with %0 "
[1]=>
string(7) "and %0nu"
[2]=>
string(7) "ll char"
[3]=>
string(1) "s"
}
-- Iteration 10 --
array(5) {
[0]=>
string(7) "with "
[1]=>
string(7) " multip"
[2]=>
string(7) "le "
[3]=>
string(7) "space c"
[4]=>
string(3) "har"
}
-- Iteration 11 --
array(6) {
[0]=>
string(7) "Testing"
[1]=>
string(7) " invali"
[2]=>
string(7) "d \k an"
[3]=>
string(7) "d \m es"
[4]=>
string(7) "cape ch"
[5]=>
string(2) "ar"
}
-- Iteration 12 --
array(4) {
[0]=>
string(7) "to chec"
[1]=>
string(7) "k with "
[2]=>
string(7) "\n and "
[3]=>
string(2) "\t"
}
Done
|