1--TEST--
2Test mb_stripos() function : usage variations - Pass different integers as $offset argument
3--EXTENSIONS--
4mbstring
5--FILE--
6<?php
7/*
8 * Test how mb_stripos() behaves when passed different integers as $offset argument
9 * The character length of $string_ascii and $string_mb is the same,
10 * and the needle appears at the same positions in both strings
11 */
12
13mb_internal_encoding('UTF-8');
14
15echo "*** Testing mb_stripos() : usage variations ***\n";
16
17$string_ascii = '+Is an English string'; //21 chars
18$needle_ascii = 'G';
19
20$string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII='); //21 chars
21$needle_mb = base64_decode('44CC');
22
23/*
24 * Loop through integers as multiples of ten for $offset argument
25 * mb_stripos should not be able to accept negative values as $offset.
26 * 60 is larger than *BYTE* count for $string_mb
27 */
28for ($i = -30; $i <= 60; $i += 10) {
29    echo "\n**-- Offset is: $i --**\n";
30    echo "-- ASCII String --\n";
31    try {
32        var_dump(mb_stripos($string_ascii, $needle_ascii, $i));
33    } catch (\ValueError $e) {
34        echo $e->getMessage() . \PHP_EOL;
35    }
36    echo "--Multibyte String --\n";
37    try {
38        var_dump(mb_stripos($string_mb, $needle_mb, $i, 'UTF-8'));
39    } catch (\ValueError $e) {
40        echo $e->getMessage() . \PHP_EOL;
41    }
42}
43
44?>
45--EXPECT--
46*** Testing mb_stripos() : usage variations ***
47
48**-- Offset is: -30 --**
49-- ASCII String --
50mb_stripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
51--Multibyte String --
52mb_stripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
53
54**-- Offset is: -20 --**
55-- ASCII String --
56int(9)
57--Multibyte String --
58int(9)
59
60**-- Offset is: -10 --**
61-- ASCII String --
62int(20)
63--Multibyte String --
64int(20)
65
66**-- Offset is: 0 --**
67-- ASCII String --
68int(9)
69--Multibyte String --
70int(9)
71
72**-- Offset is: 10 --**
73-- ASCII String --
74int(20)
75--Multibyte String --
76int(20)
77
78**-- Offset is: 20 --**
79-- ASCII String --
80int(20)
81--Multibyte String --
82int(20)
83
84**-- Offset is: 30 --**
85-- ASCII String --
86mb_stripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
87--Multibyte String --
88mb_stripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
89
90**-- Offset is: 40 --**
91-- ASCII String --
92mb_stripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
93--Multibyte String --
94mb_stripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
95
96**-- Offset is: 50 --**
97-- ASCII String --
98mb_stripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
99--Multibyte String --
100mb_stripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
101
102**-- Offset is: 60 --**
103-- ASCII String --
104mb_stripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
105--Multibyte String --
106mb_stripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
107