1--TEST--
2Test strcspn() function : usage variations - with heredoc strings, varying mask & default start and len args
3--FILE--
4<?php
5/*
6* Testing strcspn() : with heredoc string, varying mask and default start and len arguments
7*/
8
9echo "*** Testing strcspn() : with different mask strings ***\n";
10
11// initialing required variables
12// defining different heredoc strings
13$empty_heredoc = <<<EOT
14EOT;
15
16$heredoc_with_newline = <<<EOT
17\n
18
19EOT;
20
21$heredoc_with_characters = <<<EOT
22first line of heredoc string
23second line of heredoc string
24third line of heredocstring
25EOT;
26
27$heredoc_with_newline_and_tabs = <<<EOT
28hello\tworld\nhello\nworld\n
29EOT;
30
31$heredoc_with_alphanumerics = <<<EOT
32hello123world456
331234hello\t1234
34EOT;
35
36$heredoc_with_embedded_nulls = <<<EOT
37hello\0world\0hello
38\0hello\0
39EOT;
40
41$heredoc_with_hexa_octal = <<<EOT
42hello\0\100\xaaworld\0hello
43\0hello\0
44EOT;
45
46$heredoc_strings = array(
47                   $empty_heredoc,
48                   $heredoc_with_newline,
49                   $heredoc_with_characters,
50                   $heredoc_with_newline_and_tabs,
51                   $heredoc_with_alphanumerics,
52                   $heredoc_with_embedded_nulls,
53                   $heredoc_with_hexa_octal
54                   );
55
56// defining array of mask strings
57$mask_array = array(
58            "",
59            '',
60            "\n\trsti \l",
61            '\n\trsti \l',
62            "\t",
63            "t\ ",
64            '\t',
65            "\t\ ",
66            " \t",
67                    "\t\i\100\xaa"
68                   );
69
70
71// loop through each element of the arrays for string and mask arguments
72
73$count = 1;
74foreach($heredoc_strings as $str) {
75  echo "\n-- Iteration $count --\n";
76  foreach($mask_array as $mask) {
77      var_dump( strcspn($str,$mask) ); // with default start and len value
78  }
79  $count++;
80}
81
82echo "Done"
83?>
84--EXPECT--
85*** Testing strcspn() : with different mask strings ***
86
87-- Iteration 1 --
88int(0)
89int(0)
90int(0)
91int(0)
92int(0)
93int(0)
94int(0)
95int(0)
96int(0)
97int(0)
98
99-- Iteration 2 --
100int(2)
101int(2)
102int(0)
103int(2)
104int(2)
105int(2)
106int(2)
107int(2)
108int(2)
109int(2)
110
111-- Iteration 3 --
112int(86)
113int(86)
114int(1)
115int(1)
116int(86)
117int(4)
118int(4)
119int(5)
120int(5)
121int(1)
122
123-- Iteration 4 --
124int(24)
125int(24)
126int(2)
127int(2)
128int(5)
129int(24)
130int(24)
131int(5)
132int(5)
133int(5)
134
135-- Iteration 5 --
136int(31)
137int(31)
138int(2)
139int(2)
140int(26)
141int(31)
142int(31)
143int(26)
144int(26)
145int(26)
146
147-- Iteration 6 --
148int(5)
149int(5)
150int(2)
151int(2)
152int(25)
153int(25)
154int(25)
155int(25)
156int(25)
157int(25)
158
159-- Iteration 7 --
160int(5)
161int(5)
162int(2)
163int(2)
164int(27)
165int(27)
166int(27)
167int(27)
168int(27)
169int(6)
170Done
171