summaryrefslogtreecommitdiff
path: root/ext/standard/tests/strings/strrpos_variation1.phpt
blob: a7ef3e9b059d7468c1428240cff00efdd8cb6e15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
--TEST--
Test strrpos() function : usage variations - double quoted strings for 'haystack' & 'needle' arguments
--FILE--
<?php
/* Prototype  : int strrpos ( string $haystack, string $needle [, int $offset] );
 * Description: Find position of last occurrence of 'needle' in 'haystack'.
 * Source code: ext/standard/string.c
*/

/* Test strrpos() function by passing double quoted strings for 'haystack' & 'needle' arguments */

echo "*** Testing strrpos() function: with double quoted strings ***\n";
$haystack = "Hello,\t\n\0\n  $&!#%()*<=>?@hello123456he \x234 \101 ";
$needle = array(
  //regular strings
  "l",  
  "L",
  "HELLO",
  "hEllo",

  //escape characters
  "\t",  
  "\T",  //invalid input
  "     ",
  "\n",
  "\N",  //invalid input
  "
",  //new line

  //nulls
  "\0",  
  NULL,
  null,

  //boolean false
  FALSE,  
  false,

  //empty string
  "",

  //special chars
  " ",  
  "$",
  " $",
  "&",
  "!#", 
  "()",
  "<=>", 
  ">",  
  "=>",
  "?",
  "@",
  "@hEllo",

  "12345", //decimal numeric string  
  "\x23",  //hexadecimal numeric string
  "#",  //respective ASCII char of \x23
  "\101",  //octal numeric string
  "A",  //respective ASCII char of \101
  "456HEE",  //numerics + chars
  $haystack  //haystack as needle  
);
 
/* loop through to get the position of the needle in haystack string */
$count = 1;
for($index=0; $index<count($needle); $index++) {
  echo "-- Iteration $count --\n";
  var_dump( strrpos($haystack, $needle[$index]) );
  var_dump( strrpos($haystack, $needle[$index], $index) );
  $count++;
}
echo "*** Done ***";
?>
--EXPECTF--
*** Testing strrpos() function: with double quoted strings ***
-- Iteration 1 --
int(28)
int(28)
-- Iteration 2 --
bool(false)
bool(false)
-- Iteration 3 --
bool(false)
bool(false)
-- Iteration 4 --
bool(false)
bool(false)
-- Iteration 5 --
int(6)
int(6)
-- Iteration 6 --
bool(false)
bool(false)
-- Iteration 7 --
bool(false)
bool(false)
-- Iteration 8 --
int(9)
int(9)
-- Iteration 9 --
bool(false)
bool(false)
-- Iteration 10 --
int(9)
int(9)
-- Iteration 11 --
int(8)
bool(false)
-- Iteration 12 --
int(8)
bool(false)
-- Iteration 13 --
int(8)
bool(false)
-- Iteration 14 --
int(8)
bool(false)
-- Iteration 15 --
int(8)
bool(false)
-- Iteration 16 --
bool(false)
bool(false)
-- Iteration 17 --
int(43)
int(43)
-- Iteration 18 --
int(12)
bool(false)
-- Iteration 19 --
int(11)
bool(false)
-- Iteration 20 --
int(13)
bool(false)
-- Iteration 21 --
int(14)
bool(false)
-- Iteration 22 --
int(17)
bool(false)
-- Iteration 23 --
int(20)
bool(false)
-- Iteration 24 --
int(22)
bool(false)
-- Iteration 25 --
int(21)
bool(false)
-- Iteration 26 --
int(23)
bool(false)
-- Iteration 27 --
int(24)
bool(false)
-- Iteration 28 --
bool(false)
bool(false)
-- Iteration 29 --
int(30)
int(30)
-- Iteration 30 --
int(39)
int(39)
-- Iteration 31 --
int(39)
int(39)
-- Iteration 32 --
int(42)
int(42)
-- Iteration 33 --
int(42)
int(42)
-- Iteration 34 --
bool(false)
bool(false)
-- Iteration 35 --
int(0)
bool(false)
*** Done ***