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