Annotation of embedaddon/php/ext/mbstring/tests/mb_stripos_variation5_Bug45923.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test mb_stripos() function : usage variations - Pass different integers as $offset argument
3: --SKIPIF--
4: <?php
5: extension_loaded('mbstring') or die('skip');
6: function_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: Finds position of first occurrence of a string within another, case insensitive
12: * Source code: ext/mbstring/mbstring.c
13: * Alias to functions:
14: */
15:
16: /*
17: * Test how mb_stripos() behaves when passed different integers as $offset argument
18: * The character length of $string_ascii and $string_mb is the same,
19: * and the needle appears at the same positions in both strings
20: */
21:
22: mb_internal_encoding('UTF-8');
23:
24: echo "*** Testing mb_stripos() : usage variations ***\n";
25:
26: $string_ascii = b'+Is an English string'; //21 chars
27: $needle_ascii = b'G';
28:
29: $string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII='); //21 chars
30: $needle_mb = base64_decode('44CC');
31:
32: /*
33: * Loop through integers as multiples of ten for $offset argument
34: * mb_stripos should not be able to accept negative values as $offset.
35: * 60 is larger than *BYTE* count for $string_mb
36: */
37: for ($i = -10; $i <= 60; $i += 10) {
38: echo "\n**-- Offset is: $i --**\n";
39: echo "-- ASCII String --\n";
40: var_dump(mb_stripos($string_ascii, $needle_ascii, $i));
41: echo "--Multibyte String --\n";
42: var_dump(mb_stripos($string_mb, $needle_mb, $i, 'UTF-8'));
43: }
44:
45: echo "Done";
46: ?>
47:
48: --EXPECTF--
49: *** Testing mb_stripos() : usage variations ***
50:
51: **-- Offset is: -10 --**
52: -- ASCII String --
53:
54: Warning: mb_stripos(): Offset not contained in string in %s on line %d
55: bool(false)
56: --Multibyte String --
57:
58: Warning: mb_stripos(): Offset not contained in string in %s on line %d
59: bool(false)
60:
61: **-- Offset is: 0 --**
62: -- ASCII String --
63: int(9)
64: --Multibyte String --
65: int(9)
66:
67: **-- Offset is: 10 --**
68: -- ASCII String --
69: int(20)
70: --Multibyte String --
71: int(20)
72:
73: **-- Offset is: 20 --**
74: -- ASCII String --
75: int(20)
76: --Multibyte String --
77: int(20)
78:
79: **-- Offset is: 30 --**
80: -- ASCII String --
81:
82: Warning: mb_stripos(): Offset not contained in string in %s on line %d
83: bool(false)
84: --Multibyte String --
85:
86: Warning: mb_stripos(): Offset not contained in string in %s on line %d
87: bool(false)
88:
89: **-- Offset is: 40 --**
90: -- ASCII String --
91:
92: Warning: mb_stripos(): Offset not contained in string in %s on line %d
93: bool(false)
94: --Multibyte String --
95:
96: Warning: mb_stripos(): Offset not contained in string in %s on line %d
97: bool(false)
98:
99: **-- Offset is: 50 --**
100: -- ASCII String --
101:
102: Warning: mb_stripos(): Offset not contained in string in %s on line %d
103: bool(false)
104: --Multibyte String --
105:
106: Warning: mb_stripos(): Offset not contained in string in %s on line %d
107: bool(false)
108:
109: **-- Offset is: 60 --**
110: -- ASCII String --
111:
112: Warning: mb_stripos(): Offset not contained in string in %s on line %d
113: bool(false)
114: --Multibyte String --
115:
116: Warning: mb_stripos(): Offset not contained in string in %s on line %d
117: bool(false)
118: Done
119:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>