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