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/* Prototype  : int iconv_strpos(string haystack, string needle [, int offset [, string charset]])
13 * Description: Find position of first occurrence of a string within another
14 * Source code: ext/iconv/iconv.c
15 */
16
17/*
18 * Test how iconv_strpos() behaves when passed different integers as $offset argument
19 * The character length of $string_ascii and $string_mb is the same,
20 * and the needle appears at the same positions in both strings
21 */
22
23iconv_set_encoding("internal_encoding", "UTF-8");
24
25echo "*** Testing iconv_strpos() : usage variations ***\n";
26
27$string_ascii = b'+Is an English string'; //21 chars
28$needle_ascii = b'g';
29
30$string_mb = base64_decode(b'5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII='); //21 chars
31$needle_mb = base64_decode(b'44CC');
32
33/*
34 * Loop through integers as multiples of ten for $offset argument
35 * iconv_strpos should not be able to accept negative values as $offset.
36 * 60 is larger than *BYTE* count for $string_mb
37 */
38for ($i = -10; $i <= 60; $i += 10) {
39	echo "\n**-- Offset is: $i --**\n";
40	echo "-- ASCII String --\n";
41	var_dump(iconv_strpos($string_ascii, $needle_ascii, $i));
42	echo "--Multibyte String --\n";
43	var_dump(iconv_strpos($string_mb, $needle_mb, $i, 'UTF-8'));
44}
45
46echo "Done";
47?>
48
49--EXPECTF--
50*** Testing iconv_strpos() : usage variations ***
51
52**-- Offset is: -10 --**
53-- ASCII String --
54
55Warning: iconv_strpos(): Offset not contained in string. in %s on line %d
56bool(false)
57--Multibyte String --
58
59Warning: iconv_strpos(): Offset not contained in string. in %s on line %d
60bool(false)
61
62**-- Offset is: 0 --**
63-- ASCII String --
64int(9)
65--Multibyte String --
66int(9)
67
68**-- Offset is: 10 --**
69-- ASCII String --
70int(20)
71--Multibyte String --
72int(20)
73
74**-- Offset is: 20 --**
75-- ASCII String --
76int(20)
77--Multibyte String --
78int(20)
79
80**-- Offset is: 30 --**
81-- ASCII String --
82bool(false)
83--Multibyte String --
84bool(false)
85
86**-- Offset is: 40 --**
87-- ASCII String --
88bool(false)
89--Multibyte String --
90bool(false)
91
92**-- Offset is: 50 --**
93-- ASCII String --
94bool(false)
95--Multibyte String --
96bool(false)
97
98**-- Offset is: 60 --**
99-- ASCII String --
100bool(false)
101--Multibyte String --
102bool(false)
103Done