1--TEST--
2Test mb_strripos() function : usage variations - Pass different integers as $offset argument
3--SKIPIF--
4<?php
5extension_loaded('mbstring') or die('skip');
6function_exists('mb_strripos') or die("skip mb_strripos() is not available in this build");
7?>
8--FILE--
9<?php
10/* Prototype  : int mb_strripos(string haystack, string needle [, int offset [, string encoding]])
11 * Description: Finds position of last occurrence of a string within another, case insensitive
12 * Source code: ext/mbstring/mbstring.c
13 * Alias to functions:
14 */
15
16/*
17 * Test how mb_strripos() behaves when passed different integers as $offset argument
18 * The character length of $string_ascii and $string_mb is the same,
19 * and the needle appears at the same positions in both strings
20 */
21
22mb_internal_encoding('UTF-8');
23
24echo "*** Testing mb_strripos() : usage variations ***\n";
25
26$string_ascii = '+Is an English string'; //21 chars
27$needle_ascii = 'G';
28
29$string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII='); //21 chars
30$needle_mb = base64_decode('44CC');
31
32/*
33 * Loop through integers as multiples of ten for $offset argument
34 * mb_strripos should not be able to accept negative values as $offset.
35 * 60 is larger than *BYTE* count for $string_mb
36 */
37for ($i = -10; $i <= 60; $i += 10) {
38	echo "\n**-- Offset is: $i --**\n";
39	echo "-- ASCII String --\n";
40	var_dump(mb_strripos($string_ascii, $needle_ascii, $i));
41	echo "--Multibyte String --\n";
42	var_dump(mb_strripos($string_mb, $needle_mb, $i, 'UTF-8'));
43}
44
45echo "Done";
46?>
47--EXPECTF--
48*** Testing mb_strripos() : usage variations ***
49
50**-- Offset is: -10 --**
51-- ASCII String --
52int(9)
53--Multibyte String --
54int(9)
55
56**-- Offset is: 0 --**
57-- ASCII String --
58int(20)
59--Multibyte String --
60int(20)
61
62**-- Offset is: 10 --**
63-- ASCII String --
64int(20)
65--Multibyte String --
66int(20)
67
68**-- Offset is: 20 --**
69-- ASCII String --
70int(20)
71--Multibyte String --
72int(20)
73
74**-- Offset is: 30 --**
75-- ASCII String --
76
77Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
78bool(false)
79--Multibyte String --
80
81Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
82bool(false)
83
84**-- Offset is: 40 --**
85-- ASCII String --
86
87Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
88bool(false)
89--Multibyte String --
90
91Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
92bool(false)
93
94**-- Offset is: 50 --**
95-- ASCII String --
96
97Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
98bool(false)
99--Multibyte String --
100
101Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
102bool(false)
103
104**-- Offset is: 60 --**
105-- ASCII String --
106
107Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
108bool(false)
109--Multibyte String --
110
111Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
112bool(false)
113Done
114