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