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 --
111
112Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
113int(8)
114
115Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
116bool(false)
117-- Iteration 13 --
118
119Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
120int(8)
121
122Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
123bool(false)
124-- Iteration 14 --
125
126Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
127int(8)
128
129Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
130bool(false)
131-- Iteration 15 --
132
133Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
134int(8)
135
136Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d
137bool(false)
138-- Iteration 16 --
139bool(false)
140bool(false)
141-- Iteration 17 --
142int(43)
143int(43)
144-- Iteration 18 --
145int(12)
146bool(false)
147-- Iteration 19 --
148int(11)
149bool(false)
150-- Iteration 20 --
151int(13)
152bool(false)
153-- Iteration 21 --
154int(14)
155bool(false)
156-- Iteration 22 --
157int(17)
158bool(false)
159-- Iteration 23 --
160int(20)
161bool(false)
162-- Iteration 24 --
163int(22)
164bool(false)
165-- Iteration 25 --
166int(21)
167bool(false)
168-- Iteration 26 --
169int(23)
170bool(false)
171-- Iteration 27 --
172int(24)
173bool(false)
174-- Iteration 28 --
175bool(false)
176bool(false)
177-- Iteration 29 --
178int(30)
179int(30)
180-- Iteration 30 --
181int(39)
182int(39)
183-- Iteration 31 --
184int(39)
185int(39)
186-- Iteration 32 --
187int(42)
188int(42)
189-- Iteration 33 --
190int(42)
191int(42)
192-- Iteration 34 --
193bool(false)
194bool(false)
195-- Iteration 35 --
196int(0)
197bool(false)
198*** Done ***
199