1--TEST--
2Test mb_stripos() function : usage variations - Pass different integers as $offset argument
3--SKIPIF--
4<?php
5extension_loaded('mbstring') or die('skip');
6function_exists('mb_stripos') or die("skip mb_stripos() is not available in this build");
7?>
8--FILE--
9<?php
10/* Prototype  : int mb_stripos(string $haystack, string $needle [, int $offset [, string $encoding]])
11 * Description: Find position of first occurrence of a string within another, case insensitive
12 * Source code: ext/mbstring/mbstring.c
13 */
14
15/*
16 * Test how mb_stripos() behaves when passed different integers as $offset argument
17 * The character length of $string_ascii and $string_mb is the same,
18 * and the needle appears at the same positions in both strings
19 */
20
21mb_internal_encoding('UTF-8');
22
23echo "*** Testing mb_stripos() : usage variations ***\n";
24
25$string_ascii = '+Is an English string'; //21 chars
26$needle_ascii = 'G';
27
28$string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII='); //21 chars
29$needle_mb = base64_decode('44CC');
30
31/*
32 * Loop through integers as multiples of ten for $offset argument
33 * mb_stripos should not be able to accept negative values as $offset.
34 * 60 is larger than *BYTE* count for $string_mb
35 */
36for ($i = -30; $i <= 60; $i += 10) {
37	echo "\n**-- Offset is: $i --**\n";
38	echo "-- ASCII String --\n";
39	var_dump(mb_stripos($string_ascii, $needle_ascii, $i));
40	echo "--Multibyte String --\n";
41	var_dump(mb_stripos($string_mb, $needle_mb, $i, 'UTF-8'));
42}
43
44echo "Done";
45?>
46--EXPECTF--
47*** Testing mb_stripos() : usage variations ***
48
49**-- Offset is: -30 --**
50-- ASCII String --
51
52Warning: mb_stripos(): Offset not contained in string in %s on line %d
53bool(false)
54--Multibyte String --
55
56Warning: mb_stripos(): Offset not contained in string in %s on line %d
57bool(false)
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 --
91
92Warning: mb_stripos(): Offset not contained in string in %s on line %d
93bool(false)
94--Multibyte String --
95
96Warning: mb_stripos(): Offset not contained in string in %s on line %d
97bool(false)
98
99**-- Offset is: 40 --**
100-- ASCII String --
101
102Warning: mb_stripos(): Offset not contained in string in %s on line %d
103bool(false)
104--Multibyte String --
105
106Warning: mb_stripos(): Offset not contained in string in %s on line %d
107bool(false)
108
109**-- Offset is: 50 --**
110-- ASCII String --
111
112Warning: mb_stripos(): Offset not contained in string in %s on line %d
113bool(false)
114--Multibyte String --
115
116Warning: mb_stripos(): Offset not contained in string in %s on line %d
117bool(false)
118
119**-- Offset is: 60 --**
120-- ASCII String --
121
122Warning: mb_stripos(): Offset not contained in string in %s on line %d
123bool(false)
124--Multibyte String --
125
126Warning: mb_stripos(): Offset not contained in string in %s on line %d
127bool(false)
128Done
129