1--TEST--
2Test strrpos() function : usage variations - double quoted strings for 'haystack' & 'needle' arguments
3--FILE--
4<?php
5/* Prototype  : int strrpos ( string $haystack, string $needle [, int $offset] );
6 * Description: Find position of last occurrence of 'needle' in 'haystack'.
7 * Source code: ext/standard/string.c
8*/
9
10/* Test strrpos() function by passing double quoted strings for 'haystack' & 'needle' arguments */
11
12echo "*** Testing strrpos() function: with double quoted strings ***\n";
13$haystack = "Hello,\t\n\0\n  $&!#%()*<=>?@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  "()",
49  "<=>",
50  ">",
51  "=>",
52  "?",
53  "@",
54  "@hEllo",
55
56  "12345", //decimal numeric string
57  "\x23",  //hexadecimal numeric string
58  "#",  //respective ASCII char of \x23
59  "\101",  //octal numeric string
60  "A",  //respective ASCII char of \101
61  "456HEE",  //numerics + chars
62  $haystack  //haystack as needle
63);
64
65/* loop through to get the position of the needle in haystack string */
66$count = 1;
67for($index=0; $index<count($needle); $index++) {
68  echo "-- Iteration $count --\n";
69  var_dump( strrpos($haystack, $needle[$index]) );
70  var_dump( strrpos($haystack, $needle[$index], $index) );
71  $count++;
72}
73echo "*** Done ***";
74?>
75--EXPECTF--
76*** Testing strrpos() function: with double quoted strings ***
77-- Iteration 1 --
78int(28)
79int(28)
80-- Iteration 2 --
81bool(false)
82bool(false)
83-- Iteration 3 --
84bool(false)
85bool(false)
86-- Iteration 4 --
87bool(false)
88bool(false)
89-- Iteration 5 --
90int(6)
91int(6)
92-- Iteration 6 --
93bool(false)
94bool(false)
95-- Iteration 7 --
96bool(false)
97bool(false)
98-- Iteration 8 --
99int(9)
100int(9)
101-- Iteration 9 --
102bool(false)
103bool(false)
104-- Iteration 10 --
105int(9)
106int(9)
107-- Iteration 11 --
108int(8)
109bool(false)
110-- Iteration 12 --
111int(8)
112bool(false)
113-- Iteration 13 --
114int(8)
115bool(false)
116-- Iteration 14 --
117int(8)
118bool(false)
119-- Iteration 15 --
120int(8)
121bool(false)
122-- Iteration 16 --
123bool(false)
124bool(false)
125-- Iteration 17 --
126int(43)
127int(43)
128-- Iteration 18 --
129int(12)
130bool(false)
131-- Iteration 19 --
132int(11)
133bool(false)
134-- Iteration 20 --
135int(13)
136bool(false)
137-- Iteration 21 --
138int(14)
139bool(false)
140-- Iteration 22 --
141int(17)
142bool(false)
143-- Iteration 23 --
144int(20)
145bool(false)
146-- Iteration 24 --
147int(22)
148bool(false)
149-- Iteration 25 --
150int(21)
151bool(false)
152-- Iteration 26 --
153int(23)
154bool(false)
155-- Iteration 27 --
156int(24)
157bool(false)
158-- Iteration 28 --
159bool(false)
160bool(false)
161-- Iteration 29 --
162int(30)
163int(30)
164-- Iteration 30 --
165int(39)
166int(39)
167-- Iteration 31 --
168int(39)
169int(39)
170-- Iteration 32 --
171int(42)
172int(42)
173-- Iteration 33 --
174int(42)
175int(42)
176-- Iteration 34 --
177bool(false)
178bool(false)
179-- Iteration 35 --
180int(0)
181bool(false)
182*** Done ***
183