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