1--TEST--
2Test strrchr() function : usage variations - single quoted strings
3--FILE--
4<?php
5/* Prototype  : string strrchr(string $haystack, string $needle);
6 * Description: Finds the last occurrence of a character in a string.
7 * Source code: ext/standard/string.c
8*/
9
10/* Test strrchr() function by passing various single quoted strings to 'haystack' & 'needle' */
11
12echo "*** Testing strrchr() function: with various single quoted strings ***";
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',
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  '%\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  '#',  //hexadecimal numeric string
68  '\101',  //octal numeric string
69  'A',
70  '456HEE',  //numerics + chars
71  42, //needle as int(ASCII value of '*')
72  $haystack  //haystack as needle
73);
74
75/* loop through to get the position of the needle in haystack string */
76$count = 1;
77for($index=0; $index<count($needle); $index++) {
78  echo "\n-- Iteration $count --\n";
79  var_dump( strrchr($haystack, $needle[$index]) );
80  $count ++;
81}
82echo "*** Done ***";
83?>
84--EXPECTF--
85*** Testing strrchr() function: with various single quoted strings ***
86-- Iteration 1 --
87string(22) "lo123456he \x234 \101 "
88
89-- Iteration 2 --
90bool(false)
91
92-- Iteration 3 --
93string(63) "Hello,\t\n\0\n  $&!#%\o,()*+-./:;<=>?@hello123456he \x234 \101 "
94
95-- Iteration 4 --
96string(14) "he \x234 \101 "
97
98-- Iteration 5 --
99string(5) "\101 "
100
101-- Iteration 6 --
102string(5) "\101 "
103
104-- Iteration 7 --
105string(1) " "
106
107-- Iteration 8 --
108string(5) "\101 "
109
110-- Iteration 9 --
111string(5) "\101 "
112
113-- Iteration 10 --
114bool(false)
115
116-- Iteration 11 --
117string(5) "\101 "
118
119-- Iteration 12 --
120
121Deprecated: strrchr(): Non-string needles will be interpreted as strings in %s on line %d
122bool(false)
123
124-- Iteration 13 --
125
126Deprecated: strrchr(): Non-string needles will be interpreted as strings in %s on line %d
127bool(false)
128
129-- Iteration 14 --
130
131Deprecated: strrchr(): Non-string needles will be interpreted as strings in %s on line %d
132bool(false)
133
134-- Iteration 15 --
135
136Deprecated: strrchr(): Non-string needles will be interpreted as strings in %s on line %d
137bool(false)
138
139-- Iteration 16 --
140bool(false)
141
142-- Iteration 17 --
143string(1) " "
144
145-- Iteration 18 --
146string(47) "$&!#%\o,()*+-./:;<=>?@hello123456he \x234 \101 "
147
148-- Iteration 19 --
149string(1) " "
150
151-- Iteration 20 --
152string(46) "&!#%\o,()*+-./:;<=>?@hello123456he \x234 \101 "
153
154-- Iteration 21 --
155string(45) "!#%\o,()*+-./:;<=>?@hello123456he \x234 \101 "
156
157-- Iteration 22 --
158string(43) "%\o,()*+-./:;<=>?@hello123456he \x234 \101 "
159
160-- Iteration 23 --
161string(5) "\101 "
162
163-- Iteration 24 --
164string(39) "()*+-./:;<=>?@hello123456he \x234 \101 "
165
166-- Iteration 25 --
167string(37) "*+-./:;<=>?@hello123456he \x234 \101 "
168
169-- Iteration 26 --
170string(36) "+-./:;<=>?@hello123456he \x234 \101 "
171
172-- Iteration 27 --
173string(35) "-./:;<=>?@hello123456he \x234 \101 "
174
175-- Iteration 28 --
176string(34) "./:;<=>?@hello123456he \x234 \101 "
177
178-- Iteration 29 --
179string(34) "./:;<=>?@hello123456he \x234 \101 "
180
181-- Iteration 30 --
182string(32) ":;<=>?@hello123456he \x234 \101 "
183
184-- Iteration 31 --
185string(31) ";<=>?@hello123456he \x234 \101 "
186
187-- Iteration 32 --
188string(30) "<=>?@hello123456he \x234 \101 "
189
190-- Iteration 33 --
191string(28) ">?@hello123456he \x234 \101 "
192
193-- Iteration 34 --
194string(29) "=>?@hello123456he \x234 \101 "
195
196-- Iteration 35 --
197string(27) "?@hello123456he \x234 \101 "
198
199-- Iteration 36 --
200string(26) "@hello123456he \x234 \101 "
201
202-- Iteration 37 --
203string(26) "@hello123456he \x234 \101 "
204
205-- Iteration 38 --
206string(2) "1 "
207
208-- Iteration 39 --
209string(5) "\101 "
210
211-- Iteration 40 --
212string(44) "#%\o,()*+-./:;<=>?@hello123456he \x234 \101 "
213
214-- Iteration 41 --
215string(5) "\101 "
216
217-- Iteration 42 --
218bool(false)
219
220-- Iteration 43 --
221string(7) "4 \101 "
222
223-- Iteration 44 --
224
225Deprecated: strrchr(): Non-string needles will be interpreted as strings in %s on line %d
226string(37) "*+-./:;<=>?@hello123456he \x234 \101 "
227
228-- Iteration 45 --
229string(63) "Hello,\t\n\0\n  $&!#%\o,()*+-./:;<=>?@hello123456he \x234 \101 "
230*** Done ***
231