1--TEST--
2Test strcspn() function : usage variations - with varying mask & default start and len args
3--FILE--
4<?php
5/*
6* Testing strcspn() : with varying mask and default start and len arguments
7*/
8
9echo "*** Testing strcspn() : with different mask strings and default start and len arguments ***\n";
10
11// initialing required variables
12$strings = array(
13                   "",
14           '',
15           "\n",
16           '\n',
17           "hello\tworld\nhello\nworld\n",
18           'hello\tworld\nhello\nworld\n',
19           "1234hello45world\t123",
20           '1234hello45world\t123',
21           "hello\0world\012",
22           'hello\0world\012',
23           chr(0).chr(0),
24           chr(0)."hello\0world".chr(0),
25           chr(0).'hello\0world'.chr(0),
26           "hello".chr(0)."world",
27           'hello'.chr(0).'world',
28           "hello\0\100\xaaaworld",
29           'hello\0\100\xaaaworld'
30                   );
31
32// defining array of mask strings
33$mask_array = array(
34            "",
35            '',
36            "\n\trsti \l",
37            '\n\trsti \l',
38            "\t",
39            "t\ ",
40            '\t',
41            "\t\ ",
42            " \t",
43                    "\t\i\100\xa"
44                   );
45
46
47// loop through each element of the array for mask argument
48$count = 1;
49foreach($strings as $str) {
50  echo "\n-- Itearation $count --\n";
51  foreach($mask_array as $mask) {
52      var_dump( strcspn($str,$mask) );
53  }
54  $count++;
55}
56
57echo "Done"
58?>
59--EXPECT--
60*** Testing strcspn() : with different mask strings and default start and len arguments ***
61
62-- Itearation 1 --
63int(0)
64int(0)
65int(0)
66int(0)
67int(0)
68int(0)
69int(0)
70int(0)
71int(0)
72int(0)
73
74-- Itearation 2 --
75int(0)
76int(0)
77int(0)
78int(0)
79int(0)
80int(0)
81int(0)
82int(0)
83int(0)
84int(0)
85
86-- Itearation 3 --
87int(1)
88int(1)
89int(0)
90int(1)
91int(1)
92int(1)
93int(1)
94int(1)
95int(1)
96int(0)
97
98-- Itearation 4 --
99int(2)
100int(2)
101int(0)
102int(0)
103int(2)
104int(0)
105int(0)
106int(0)
107int(2)
108int(0)
109
110-- Itearation 5 --
111int(24)
112int(24)
113int(2)
114int(2)
115int(5)
116int(24)
117int(24)
118int(5)
119int(5)
120int(5)
121
122-- Itearation 6 --
123int(28)
124int(28)
125int(2)
126int(2)
127int(28)
128int(5)
129int(5)
130int(5)
131int(28)
132int(5)
133
134-- Itearation 7 --
135int(20)
136int(20)
137int(6)
138int(6)
139int(16)
140int(20)
141int(20)
142int(16)
143int(16)
144int(16)
145
146-- Itearation 8 --
147int(21)
148int(21)
149int(6)
150int(6)
151int(21)
152int(16)
153int(16)
154int(16)
155int(21)
156int(16)
157
158-- Itearation 9 --
159int(5)
160int(5)
161int(2)
162int(2)
163int(12)
164int(12)
165int(12)
166int(12)
167int(12)
168int(11)
169
170-- Itearation 10 --
171int(16)
172int(16)
173int(2)
174int(2)
175int(16)
176int(5)
177int(5)
178int(5)
179int(16)
180int(5)
181
182-- Itearation 11 --
183int(0)
184int(0)
185int(2)
186int(2)
187int(2)
188int(2)
189int(2)
190int(2)
191int(2)
192int(2)
193
194-- Itearation 12 --
195int(0)
196int(0)
197int(3)
198int(3)
199int(13)
200int(13)
201int(13)
202int(13)
203int(13)
204int(13)
205
206-- Itearation 13 --
207int(0)
208int(0)
209int(3)
210int(3)
211int(14)
212int(6)
213int(6)
214int(6)
215int(14)
216int(6)
217
218-- Itearation 14 --
219int(5)
220int(5)
221int(2)
222int(2)
223int(11)
224int(11)
225int(11)
226int(11)
227int(11)
228int(11)
229
230-- Itearation 15 --
231int(5)
232int(5)
233int(2)
234int(2)
235int(11)
236int(11)
237int(11)
238int(11)
239int(11)
240int(11)
241
242-- Itearation 16 --
243int(5)
244int(5)
245int(2)
246int(2)
247int(14)
248int(14)
249int(14)
250int(14)
251int(14)
252int(6)
253
254-- Itearation 17 --
255int(21)
256int(21)
257int(2)
258int(2)
259int(21)
260int(5)
261int(5)
262int(5)
263int(21)
264int(5)
265Done
266