1--TEST--
2Test stripos() function : usage variations - double quoted strings for 'haystack' & 'needle' arguments
3--FILE--
4<?php
5/* Prototype  : int stripos ( string $haystack, string $needle [, int $offset] );
6 * Description: Find position of first occurrence of a case-insensitive string
7 * Source code: ext/standard/string.c
8*/
9
10/* Test stripos() function by passing double quoted strings for 'haystack' & 'needle' arguments */
11
12echo "*** Testing stripos() function: with double quoted strings ***\n";
13$haystack = "Hello,\t\n\0\n  $&!#%\o,()*+-./:;<=>?@hello123456he \x234 \101 ";
14$needle = array(
15  //regular strings
16  "l",
17  "L",
18  "HELLO",
19  "hEllo",
20
21  //escape characters
22  "\t",
23  "\T",  //invalid input
24  "     ",
25  "\n",
26  "\N",  //invalid input
27  "
28",  //new line
29
30  //nulls
31  "\0",
32  NULL,
33  null,
34
35  //boolean false
36  FALSE,
37  false,
38
39  //empty string
40  "",
41
42  //special chars
43  " ",
44  "$",
45  " $",
46  "&",
47  "!#",
48  "%\o",
49  "\o,",
50  "()",
51  "*+",
52  "+",
53  "-",
54  ".",
55  ".;",
56  ":;",
57  ";",
58  "<=>",
59  ">",
60  "=>",
61  "?",
62  "@",
63  "@hEllo",
64
65  "12345", //decimal numeric string
66  "\x23",  //hexadecimal numeric string
67  "#",  //respective ASCII char of \x23
68  "\101",  //octal numeric string
69  "A",  //respective ASCII char of \101
70  "456HEE",  //numerics + chars
71  $haystack  //haystack as needle
72);
73
74/* loop through to get the position of the needle in haystack string */
75$count = 1;
76for($index=0; $index<count($needle); $index++) {
77  echo "-- Iteration $count --\n";
78  var_dump( stripos($haystack, $needle[$index]) );
79  var_dump( stripos($haystack, $needle[$index], $index) );
80  $count++;
81}
82echo "*** Done ***";
83?>
84--EXPECTF--
85*** Testing stripos() function: with double quoted strings ***
86-- Iteration 1 --
87int(2)
88int(2)
89-- Iteration 2 --
90int(2)
91int(2)
92-- Iteration 3 --
93int(0)
94int(34)
95-- Iteration 4 --
96int(0)
97int(34)
98-- Iteration 5 --
99int(6)
100int(6)
101-- Iteration 6 --
102bool(false)
103bool(false)
104-- Iteration 7 --
105bool(false)
106bool(false)
107-- Iteration 8 --
108int(7)
109int(7)
110-- Iteration 9 --
111bool(false)
112bool(false)
113-- Iteration 10 --
114int(7)
115int(9)
116-- Iteration 11 --
117int(8)
118bool(false)
119-- Iteration 12 --
120int(8)
121bool(false)
122-- Iteration 13 --
123int(8)
124bool(false)
125-- Iteration 14 --
126int(8)
127bool(false)
128-- Iteration 15 --
129int(8)
130bool(false)
131-- Iteration 16 --
132bool(false)
133bool(false)
134-- Iteration 17 --
135int(10)
136int(47)
137-- Iteration 18 --
138int(12)
139bool(false)
140-- Iteration 19 --
141int(11)
142bool(false)
143-- Iteration 20 --
144int(13)
145bool(false)
146-- Iteration 21 --
147int(14)
148bool(false)
149-- Iteration 22 --
150int(16)
151bool(false)
152-- Iteration 23 --
153int(17)
154bool(false)
155-- Iteration 24 --
156int(20)
157bool(false)
158-- Iteration 25 --
159int(22)
160bool(false)
161-- Iteration 26 --
162int(23)
163bool(false)
164-- Iteration 27 --
165int(24)
166bool(false)
167-- Iteration 28 --
168int(25)
169bool(false)
170-- Iteration 29 --
171bool(false)
172bool(false)
173-- Iteration 30 --
174int(27)
175bool(false)
176-- Iteration 31 --
177int(28)
178bool(false)
179-- Iteration 32 --
180int(29)
181bool(false)
182-- Iteration 33 --
183int(31)
184bool(false)
185-- Iteration 34 --
186int(30)
187bool(false)
188-- Iteration 35 --
189int(32)
190bool(false)
191-- Iteration 36 --
192int(33)
193bool(false)
194-- Iteration 37 --
195int(33)
196bool(false)
197-- Iteration 38 --
198int(39)
199int(39)
200-- Iteration 39 --
201int(15)
202int(48)
203-- Iteration 40 --
204int(15)
205int(48)
206-- Iteration 41 --
207int(51)
208int(51)
209-- Iteration 42 --
210int(51)
211int(51)
212-- Iteration 43 --
213bool(false)
214bool(false)
215-- Iteration 44 --
216int(0)
217bool(false)
218*** Done ***
219