summaryrefslogtreecommitdiff
path: root/ext/standard/tests/strings/strrpos_variation8.phpt
blob: de6bce2f33fa438e863d1adae40be6a9a0cb108f (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
--TEST--
Test strrpos() function : usage variations - repetitive chars for 'haystack' argument
--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 with strings containing multiple occurrences of 'needle' in the 'haystack'
 *  and with various needles & offsets
*/

echo "*** Testing strrpos() function: strings repetitive chars ***\n";
$haystack = "ababababAbaBa";
$needle = "aba";

/* loop through to consider various offsets in getting the position of the needle in haystack string */
$count = 1;
for($offset = -1; $offset <= strlen($haystack); $offset++ ) {
  echo "-- Iteration $count --\n";
  var_dump( strrpos($haystack, $needle, $offset) );
  $count++;
}
echo "*** Done ***";
?>
--EXPECTF--
*** Testing strrpos() function: strings repetitive chars ***
-- Iteration 1 --
int(4)
-- Iteration 2 --
int(4)
-- Iteration 3 --
int(4)
-- Iteration 4 --
int(4)
-- Iteration 5 --
int(4)
-- Iteration 6 --
int(4)
-- Iteration 7 --
bool(false)
-- Iteration 8 --
bool(false)
-- Iteration 9 --
bool(false)
-- Iteration 10 --
bool(false)
-- Iteration 11 --
bool(false)
-- Iteration 12 --
bool(false)
-- Iteration 13 --
bool(false)
-- Iteration 14 --
bool(false)
-- Iteration 15 --
bool(false)
*** Done ***