1--TEST--
2Test strspn() function : usage variations - with heredoc strings, 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 heredoc string, varying mask and default start and len arguments
14*/
15
16echo "*** Testing strspn() : with different mask strings ***\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		    "fh\ne\trlsti \l",
69		    'fieh\n\trlsti \l',
70		    "\t",
71		    "lt\ ",
72		    'l\t',
73		    "fl\t\eh ",
74		    "l \te",
75                    "lf\the\i\100\xaa"
76                   );
77
78
79// loop through each element of the array for different heredoc and mask strings
80
81$count = 1;
82
83foreach($heredoc_strings as $str)  {
84  echo "\n-- Iteration $count --\n";
85  foreach($mask_array as $mask)  {
86      var_dump( strspn($str,$mask) ); // with default start and len value
87  }
88  $count++;
89}
90
91echo "Done"
92?>
93--EXPECTF--
94*** Testing strspn() : with different mask strings ***
95
96-- Iteration 1 --
97int(0)
98int(0)
99int(0)
100int(0)
101int(0)
102int(0)
103int(0)
104int(0)
105int(0)
106int(0)
107
108-- Iteration 2 --
109int(0)
110int(0)
111int(2)
112int(0)
113int(0)
114int(0)
115int(0)
116int(0)
117int(0)
118int(0)
119
120-- Iteration 3 --
121int(0)
122int(0)
123int(8)
124int(11)
125int(0)
126int(0)
127int(0)
128int(1)
129int(0)
130int(2)
131
132-- Iteration 4 --
133int(0)
134int(0)
135int(4)
136int(4)
137int(0)
138int(0)
139int(0)
140int(1)
141int(0)
142int(4)
143
144-- Iteration 5 --
145int(0)
146int(0)
147int(4)
148int(4)
149int(0)
150int(0)
151int(0)
152int(1)
153int(0)
154int(4)
155
156-- Iteration 6 --
157int(0)
158int(0)
159int(4)
160int(4)
161int(0)
162int(0)
163int(0)
164int(1)
165int(0)
166int(4)
167
168-- Iteration 7 --
169int(0)
170int(0)
171int(4)
172int(4)
173int(0)
174int(0)
175int(0)
176int(1)
177int(0)
178int(4)
179Done
180