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 = b'+Is an English string'; //21 chars
27$needle_ascii = b'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
48--EXPECTF--
49*** Testing mb_strripos() : usage variations ***
50
51**-- Offset is: -10 --**
52-- ASCII String --
53int(9)
54--Multibyte String --
55int(9)
56
57**-- Offset is: 0 --**
58-- ASCII String --
59int(20)
60--Multibyte String --
61int(20)
62
63**-- Offset is: 10 --**
64-- ASCII String --
65int(20)
66--Multibyte String --
67int(20)
68
69**-- Offset is: 20 --**
70-- ASCII String --
71int(20)
72--Multibyte String --
73int(20)
74
75**-- Offset is: 30 --**
76-- ASCII String --
77
78Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
79bool(false)
80--Multibyte String --
81
82Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
83bool(false)
84
85**-- Offset is: 40 --**
86-- ASCII String --
87
88Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
89bool(false)
90--Multibyte String --
91
92Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
93bool(false)
94
95**-- Offset is: 50 --**
96-- ASCII String --
97
98Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
99bool(false)
100--Multibyte String --
101
102Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
103bool(false)
104
105**-- Offset is: 60 --**
106-- ASCII String --
107
108Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
109bool(false)
110--Multibyte String --
111
112Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
113bool(false)
114Done
115
116