Annotation of embedaddon/php/ext/mbstring/tests/mb_strripos_variation5_Bug45923.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test mb_strripos() function : usage variations - Pass different integers as $offset argument
3: --SKIPIF--
4: <?php
5: extension_loaded('mbstring') or die('skip');
6: function_exists('mb_strripos') or die("skip mb_strripos() is not available in this build");
7: ?>
8: --FILE--
9: <?php
10: /* Prototype : int mb_strripos(string haystack, string needle [, int offset [, string encoding]])
11: * Description: Finds position of last 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_strripos() 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_strripos() : 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_strripos 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_strripos($string_ascii, $needle_ascii, $i));
41: echo "--Multibyte String --\n";
42: var_dump(mb_strripos($string_mb, $needle_mb, $i, 'UTF-8'));
43: }
44:
45: echo "Done";
46: ?>
47:
48: --EXPECTF--
49: *** Testing mb_strripos() : usage variations ***
50:
51: **-- Offset is: -10 --**
52: -- ASCII String --
53: int(9)
54: --Multibyte String --
55: int(9)
56:
57: **-- Offset is: 0 --**
58: -- ASCII String --
59: int(20)
60: --Multibyte String --
61: int(20)
62:
63: **-- Offset is: 10 --**
64: -- ASCII String --
65: int(20)
66: --Multibyte String --
67: int(20)
68:
69: **-- Offset is: 20 --**
70: -- ASCII String --
71: int(20)
72: --Multibyte String --
73: int(20)
74:
75: **-- Offset is: 30 --**
76: -- ASCII String --
77:
78: Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
79: bool(false)
80: --Multibyte String --
81:
82: Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
83: bool(false)
84:
85: **-- Offset is: 40 --**
86: -- ASCII String --
87:
88: Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
89: bool(false)
90: --Multibyte String --
91:
92: Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
93: bool(false)
94:
95: **-- Offset is: 50 --**
96: -- ASCII String --
97:
98: Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
99: bool(false)
100: --Multibyte String --
101:
102: Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
103: bool(false)
104:
105: **-- Offset is: 60 --**
106: -- ASCII String --
107:
108: Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
109: bool(false)
110: --Multibyte String --
111:
112: Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
113: bool(false)
114: Done
115:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>