1--TEST--
2Test strspn() function : usage variations - with heredoc strings, varying start and default 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 heredoc string, varying start and default len arguments
14*/
15
16echo "*** Testing strspn() : with different start values ***\n";
17
18// initialing required variables
19// defining different heredoc strings
20$empty_heredoc = <<<EOT
21EOT;
22
23$heredoc_with_newline = <<<EOT
24\n
25
26EOT;
27
28$heredoc_with_characters = <<<EOT
29first line of heredoc string
30second line of heredoc string
31third line of heredocstring
32EOT;
33
34$heredoc_with_newline_and_tabs = <<<EOT
35hello\tworld\nhello\nworld\n
36EOT;
37
38$heredoc_with_alphanumerics = <<<EOT
39hello123world456
401234hello\t1234
41EOT;
42
43$heredoc_with_embedded_nulls = <<<EOT
44hello\0world\0hello
45\0hello\0
46EOT;
47
48$heredoc_with_hexa_octal = <<<EOT
49hello\0\100\xaaworld\0hello
50\0hello\0
51EOT;
52
53// defining array of different heredoc strings
54$heredoc_strings = array(
55                   $empty_heredoc,
56                   $heredoc_with_newline,
57                   $heredoc_with_characters,
58                   $heredoc_with_newline_and_tabs,
59                   $heredoc_with_alphanumerics,
60                   $heredoc_with_embedded_nulls,
61                   $heredoc_with_hexa_octal
62                   );
63
64// defining array of different mask strings
65$mask_array = array(
66		    "",
67		    '',
68		    "f\nh\trstie \l",
69		    'f\n\thrstei \l',
70		    "\t",
71		    "t\ e",
72		    '\t',
73		    "f\te\h ",
74		    " \t",
75                    "f\t\ih\100e\xa"
76                   );
77
78// defining array of different start values
79$start_array = array(
80		    0,
81		    1,
82  	            2,
83		    -1,
84		    -2,
85		    2147483647,  // max positive integer
86		    -2147483648,  // min negative integer
87                   );
88
89
90// loop through each element of the array for heredoc strings, mask strings and start values
91
92$count = 1;
93
94foreach($heredoc_strings as $str)  {
95  echo "\n-- Iteration $count --\n";
96  foreach($mask_array as $mask)  {
97    foreach($start_array as $start)  {
98      var_dump( strspn($str,$mask,$start) );  // with default len value
99    }
100  }
101  $count++;
102}
103
104echo "Done"
105?>
106--EXPECT--
107*** Testing strspn() : with different start values ***
108
109-- Iteration 1 --
110int(0)
111bool(false)
112bool(false)
113int(0)
114int(0)
115bool(false)
116int(0)
117int(0)
118bool(false)
119bool(false)
120int(0)
121int(0)
122bool(false)
123int(0)
124int(0)
125bool(false)
126bool(false)
127int(0)
128int(0)
129bool(false)
130int(0)
131int(0)
132bool(false)
133bool(false)
134int(0)
135int(0)
136bool(false)
137int(0)
138int(0)
139bool(false)
140bool(false)
141int(0)
142int(0)
143bool(false)
144int(0)
145int(0)
146bool(false)
147bool(false)
148int(0)
149int(0)
150bool(false)
151int(0)
152int(0)
153bool(false)
154bool(false)
155int(0)
156int(0)
157bool(false)
158int(0)
159int(0)
160bool(false)
161bool(false)
162int(0)
163int(0)
164bool(false)
165int(0)
166int(0)
167bool(false)
168bool(false)
169int(0)
170int(0)
171bool(false)
172int(0)
173int(0)
174bool(false)
175bool(false)
176int(0)
177int(0)
178bool(false)
179int(0)
180
181-- Iteration 2 --
182int(0)
183int(0)
184int(0)
185int(0)
186int(0)
187bool(false)
188int(0)
189int(0)
190int(0)
191int(0)
192int(0)
193int(0)
194bool(false)
195int(0)
196int(2)
197int(1)
198int(0)
199int(1)
200int(2)
201bool(false)
202int(2)
203int(0)
204int(0)
205int(0)
206int(0)
207int(0)
208bool(false)
209int(0)
210int(0)
211int(0)
212int(0)
213int(0)
214int(0)
215bool(false)
216int(0)
217int(0)
218int(0)
219int(0)
220int(0)
221int(0)
222bool(false)
223int(0)
224int(0)
225int(0)
226int(0)
227int(0)
228int(0)
229bool(false)
230int(0)
231int(0)
232int(0)
233int(0)
234int(0)
235int(0)
236bool(false)
237int(0)
238int(0)
239int(0)
240int(0)
241int(0)
242int(0)
243bool(false)
244int(0)
245int(2)
246int(1)
247int(0)
248int(1)
249int(2)
250bool(false)
251int(2)
252
253-- Iteration 3 --
254int(0)
255int(0)
256int(0)
257int(0)
258int(0)
259bool(false)
260int(0)
261int(0)
262int(0)
263int(0)
264int(0)
265int(0)
266bool(false)
267int(0)
268int(8)
269int(7)
270int(6)
271int(0)
272int(0)
273bool(false)
274int(8)
275int(11)
276int(10)
277int(9)
278int(0)
279int(1)
280bool(false)
281int(11)
282int(0)
283int(0)
284int(0)
285int(0)
286int(0)
287bool(false)
288int(0)
289int(0)
290int(0)
291int(0)
292int(0)
293int(0)
294bool(false)
295int(0)
296int(0)
297int(0)
298int(0)
299int(0)
300int(0)
301bool(false)
302int(0)
303int(1)
304int(0)
305int(0)
306int(0)
307int(0)
308bool(false)
309int(1)
310int(0)
311int(0)
312int(0)
313int(0)
314int(0)
315bool(false)
316int(0)
317int(2)
318int(1)
319int(0)
320int(0)
321int(0)
322bool(false)
323int(2)
324
325-- Iteration 4 --
326int(0)
327int(0)
328int(0)
329int(0)
330int(0)
331bool(false)
332int(0)
333int(0)
334int(0)
335int(0)
336int(0)
337int(0)
338bool(false)
339int(0)
340int(4)
341int(3)
342int(2)
343int(1)
344int(0)
345bool(false)
346int(4)
347int(4)
348int(3)
349int(2)
350int(0)
351int(0)
352bool(false)
353int(4)
354int(0)
355int(0)
356int(0)
357int(0)
358int(0)
359bool(false)
360int(0)
361int(0)
362int(1)
363int(0)
364int(0)
365int(0)
366bool(false)
367int(0)
368int(0)
369int(0)
370int(0)
371int(0)
372int(0)
373bool(false)
374int(0)
375int(2)
376int(1)
377int(0)
378int(0)
379int(0)
380bool(false)
381int(2)
382int(0)
383int(0)
384int(0)
385int(0)
386int(0)
387bool(false)
388int(0)
389int(2)
390int(1)
391int(0)
392int(1)
393int(0)
394bool(false)
395int(2)
396
397-- Iteration 5 --
398int(0)
399int(0)
400int(0)
401int(0)
402int(0)
403bool(false)
404int(0)
405int(0)
406int(0)
407int(0)
408int(0)
409int(0)
410bool(false)
411int(0)
412int(4)
413int(3)
414int(2)
415int(0)
416int(0)
417bool(false)
418int(4)
419int(4)
420int(3)
421int(2)
422int(0)
423int(0)
424bool(false)
425int(4)
426int(0)
427int(0)
428int(0)
429int(0)
430int(0)
431bool(false)
432int(0)
433int(0)
434int(1)
435int(0)
436int(0)
437int(0)
438bool(false)
439int(0)
440int(0)
441int(0)
442int(0)
443int(0)
444int(0)
445bool(false)
446int(0)
447int(2)
448int(1)
449int(0)
450int(0)
451int(0)
452bool(false)
453int(2)
454int(0)
455int(0)
456int(0)
457int(0)
458int(0)
459bool(false)
460int(0)
461int(2)
462int(1)
463int(0)
464int(0)
465int(0)
466bool(false)
467int(2)
468
469-- Iteration 6 --
470int(0)
471int(0)
472int(0)
473int(0)
474int(0)
475bool(false)
476int(0)
477int(0)
478int(0)
479int(0)
480int(0)
481int(0)
482bool(false)
483int(0)
484int(4)
485int(3)
486int(2)
487int(0)
488int(0)
489bool(false)
490int(4)
491int(4)
492int(3)
493int(2)
494int(0)
495int(0)
496bool(false)
497int(4)
498int(0)
499int(0)
500int(0)
501int(0)
502int(0)
503bool(false)
504int(0)
505int(0)
506int(1)
507int(0)
508int(0)
509int(0)
510bool(false)
511int(0)
512int(0)
513int(0)
514int(0)
515int(0)
516int(0)
517bool(false)
518int(0)
519int(2)
520int(1)
521int(0)
522int(0)
523int(0)
524bool(false)
525int(2)
526int(0)
527int(0)
528int(0)
529int(0)
530int(0)
531bool(false)
532int(0)
533int(2)
534int(1)
535int(0)
536int(0)
537int(0)
538bool(false)
539int(2)
540
541-- Iteration 7 --
542int(0)
543int(0)
544int(0)
545int(0)
546int(0)
547bool(false)
548int(0)
549int(0)
550int(0)
551int(0)
552int(0)
553int(0)
554bool(false)
555int(0)
556int(4)
557int(3)
558int(2)
559int(0)
560int(0)
561bool(false)
562int(4)
563int(4)
564int(3)
565int(2)
566int(0)
567int(0)
568bool(false)
569int(4)
570int(0)
571int(0)
572int(0)
573int(0)
574int(0)
575bool(false)
576int(0)
577int(0)
578int(1)
579int(0)
580int(0)
581int(0)
582bool(false)
583int(0)
584int(0)
585int(0)
586int(0)
587int(0)
588int(0)
589bool(false)
590int(0)
591int(2)
592int(1)
593int(0)
594int(0)
595int(0)
596bool(false)
597int(2)
598int(0)
599int(0)
600int(0)
601int(0)
602int(0)
603bool(false)
604int(0)
605int(2)
606int(1)
607int(0)
608int(0)
609int(0)
610bool(false)
611int(2)
612Done
613