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 = '+Is an English string'; //21 chars
28$needle_ascii = 'g';
29
30$string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII='); //21 chars
31$needle_mb = base64_decode('44CC');
32
33/*
34 * Loop through integers as multiples of ten for $offset argument
35 * 60 is larger than *BYTE* count for $string_mb
36 */
37for ($i = -30; $i <= 60; $i += 10) {
38	echo "\n**-- Offset is: $i --**\n";
39	echo "-- ASCII String --\n";
40	var_dump(iconv_strpos($string_ascii, $needle_ascii, $i));
41	echo "--Multibyte String --\n";
42	var_dump(iconv_strpos($string_mb, $needle_mb, $i, 'UTF-8'));
43}
44
45echo "Done";
46?>
47--EXPECTF--
48*** Testing iconv_strpos() : usage variations ***
49
50**-- Offset is: -30 --**
51-- ASCII String --
52
53Warning: iconv_strpos(): Offset not contained in string. in %s on line %d
54bool(false)
55--Multibyte String --
56
57Warning: iconv_strpos(): Offset not contained in string. in %s on line %d
58bool(false)
59
60**-- Offset is: -20 --**
61-- ASCII String --
62int(9)
63--Multibyte String --
64int(9)
65
66**-- Offset is: -10 --**
67-- ASCII String --
68int(20)
69--Multibyte String --
70int(20)
71
72**-- Offset is: 0 --**
73-- ASCII String --
74int(9)
75--Multibyte String --
76int(9)
77
78**-- Offset is: 10 --**
79-- ASCII String --
80int(20)
81--Multibyte String --
82int(20)
83
84**-- Offset is: 20 --**
85-- ASCII String --
86int(20)
87--Multibyte String --
88int(20)
89
90**-- Offset is: 30 --**
91-- ASCII String --
92bool(false)
93--Multibyte String --
94bool(false)
95
96**-- Offset is: 40 --**
97-- ASCII String --
98bool(false)
99--Multibyte String --
100bool(false)
101
102**-- Offset is: 50 --**
103-- ASCII String --
104bool(false)
105--Multibyte String --
106bool(false)
107
108**-- Offset is: 60 --**
109-- ASCII String --
110bool(false)
111--Multibyte String --
112bool(false)
113Done
114