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