Annotation of embedaddon/php/ext/mbstring/tests/bug43841.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test mb_strrpos() function : mb_strrpos offset is byte count for negative values
3: --SKIPIF--
4: <?php
5: extension_loaded('mbstring') or die('skip');
6: function_exists('mb_strrpos') or die("skip mb_strrpos() is not available in this build");
7: ?>
8: --FILE--
9: <?php
10: /* Prototype : int mb_strrpos(string $haystack, string $needle [, int $offset [, string $encoding]])
11: * Description: Find position of last occurrence of a string within another
12: * Source code: ext/mbstring/mbstring.c
13: */
14:
15: /*
16: * Test that mb_strrpos offset is byte count for negative values (should be character count)
17: */
18:
19: $offsets = array(-25, -24, -13, -12);
20: $string_mb =
21: base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvv
22: JfvvJjvvJnjgII=');
23: $needle = base64_decode('44CC');
24:
25: foreach ($offsets as $i) {
26: echo "\n-- Offset is $i --\n";
27: echo "Multibyte String:\n";
28: var_dump( mb_strrpos($string_mb, $needle, $i, 'UTF-8') );
29: echo "ASCII String:\n";
30: echo "mb_strrpos:\n";
31: var_dump(mb_strrpos(b'This is na English ta', b'a', $i));
32: echo "strrpos:\n";
33: var_dump(strrpos(b'This is na English ta', b'a', $i));
34: }
35: ?>
36:
37: --EXPECTF--
38:
39: -- Offset is -25 --
40: Multibyte String:
41:
42: Warning: mb_strrpos(): Offset is greater than the length of haystack string in %s on line %d
43: bool(false)
44: ASCII String:
45: mb_strrpos:
46:
47: Warning: mb_strrpos(): Offset is greater than the length of haystack string in %s on line %d
48: bool(false)
49: strrpos:
50:
51: Warning: strrpos(): Offset is greater than the length of haystack string in %s on line %d
52: bool(false)
53:
54: -- Offset is -24 --
55: Multibyte String:
56:
57: Warning: mb_strrpos(): Offset is greater than the length of haystack string in %s on line %d
58: bool(false)
59: ASCII String:
60: mb_strrpos:
61:
62: Warning: mb_strrpos(): Offset is greater than the length of haystack string in %s on line %d
63: bool(false)
64: strrpos:
65:
66: Warning: strrpos(): Offset is greater than the length of haystack string in %s on line %d
67: bool(false)
68:
69: -- Offset is -13 --
70: Multibyte String:
71: bool(false)
72: ASCII String:
73: mb_strrpos:
74: bool(false)
75: strrpos:
76: bool(false)
77:
78: -- Offset is -12 --
79: Multibyte String:
80: int(9)
81: ASCII String:
82: mb_strrpos:
83: int(9)
84: strrpos:
85: int(9)
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>