1--TEST--
2Test mb_strpos() function : usage variations - Pass different integers as $offset argument
3--EXTENSIONS--
4mbstring
5--FILE--
6<?php
7/*
8 * Test how mb_strpos() 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_strpos() : 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 * 60 is larger than *BYTE* count for $string_mb
26 */
27for ($i = -30; $i <= 60; $i += 10) {
28    echo "\n**-- Offset is: $i --**\n";
29    echo "-- ASCII String --\n";
30    try {
31        var_dump(mb_strpos($string_ascii, $needle_ascii, $i));
32    } catch (\ValueError $e) {
33        echo $e->getMessage() . \PHP_EOL;
34    }
35
36    echo "--Multibyte String --\n";
37    try {
38        var_dump(mb_strpos($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_strpos() : usage variations ***
47
48**-- Offset is: -30 --**
49-- ASCII String --
50mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
51--Multibyte String --
52mb_strpos(): 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_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
87--Multibyte String --
88mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
89
90**-- Offset is: 40 --**
91-- ASCII String --
92mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
93--Multibyte String --
94mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
95
96**-- Offset is: 50 --**
97-- ASCII String --
98mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
99--Multibyte String --
100mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
101
102**-- Offset is: 60 --**
103-- ASCII String --
104mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
105--Multibyte String --
106mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
107