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
|
--TEST--
Test str_split() function : usage variations - different integer values for 'split_length' with heredoc 'str'
--SKIPIF--
<?php
if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only");
?>
--FILE--
<?php
/* Prototype : array str_split(string $str [, int $split_length])
* Description: Convert a string to an array. If split_length is
specified, break the string down into chunks each
split_length characters long.
* Source code: ext/standard/string.c
* Alias to functions: none
*/
/*
* passing different integer values for 'split_length' and heredoc string as 'str' argument to str_split()
*/
echo "*** Testing str_split() : different intger values for 'split_length' with heredoc 'str' ***\n";
//Initialise variables
$str = <<<EOT
string with 123,escape char \t.
EOT;
//different values for 'split_length'
$values = array (
0,
1,
-123, //negative integer
0234, //octal number
0x1A, //hexadecimal number
2147483647, //max positive integer number
2147483648, //max positive integer+1
-2147483648, //min negative integer
);
//loop through each element of $values for 'split_length'
for($count = 0; $count < count($values); $count++) {
echo "-- Iteration ".($count + 1)." --\n";
var_dump( str_split($str, $values[$count]) );
}
echo "Done"
?>
--EXPECTF--
*** Testing str_split() : different intger values for 'split_length' with heredoc 'str' ***
-- Iteration 1 --
Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
bool(false)
-- Iteration 2 --
array(30) {
[0]=>
string(1) "s"
[1]=>
string(1) "t"
[2]=>
string(1) "r"
[3]=>
string(1) "i"
[4]=>
string(1) "n"
[5]=>
string(1) "g"
[6]=>
string(1) " "
[7]=>
string(1) "w"
[8]=>
string(1) "i"
[9]=>
string(1) "t"
[10]=>
string(1) "h"
[11]=>
string(1) " "
[12]=>
string(1) "1"
[13]=>
string(1) "2"
[14]=>
string(1) "3"
[15]=>
string(1) ","
[16]=>
string(1) "e"
[17]=>
string(1) "s"
[18]=>
string(1) "c"
[19]=>
string(1) "a"
[20]=>
string(1) "p"
[21]=>
string(1) "e"
[22]=>
string(1) " "
[23]=>
string(1) "c"
[24]=>
string(1) "h"
[25]=>
string(1) "a"
[26]=>
string(1) "r"
[27]=>
string(1) " "
[28]=>
string(1) " "
[29]=>
string(1) "."
}
-- Iteration 3 --
Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
bool(false)
-- Iteration 4 --
array(1) {
[0]=>
string(30) "string with 123,escape char ."
}
-- Iteration 5 --
array(2) {
[0]=>
string(26) "string with 123,escape cha"
[1]=>
string(4) "r ."
}
-- Iteration 6 --
array(1) {
[0]=>
string(30) "string with 123,escape char ."
}
-- Iteration 7 --
array(1) {
[0]=>
string(30) "string with 123,escape char ."
}
-- Iteration 8 --
Warning: str_split(): The length of each segment must be greater than zero in %s on line %d
bool(false)
Done
|