xref: /PHP-5.5/ext/mbstring/tests/bug43841.phpt (revision b2b61661)
1--TEST--
2Test mb_strrpos() function : mb_strrpos offset is byte count for negative values
3--SKIPIF--
4<?php
5extension_loaded('mbstring') or die('skip');
6function_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 =
21base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvv
22JfvvJjvvJnjgII=');
23$needle = base64_decode('44CC');
24
25foreach ($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 --
40Multibyte String:
41
42Warning: mb_strrpos(): Offset is greater than the length of haystack string in %s on line %d
43bool(false)
44ASCII String:
45mb_strrpos:
46
47Warning: mb_strrpos(): Offset is greater than the length of haystack string in %s on line %d
48bool(false)
49strrpos:
50
51Warning: strrpos(): Offset is greater than the length of haystack string in %s on line %d
52bool(false)
53
54-- Offset is -24 --
55Multibyte String:
56
57Warning: mb_strrpos(): Offset is greater than the length of haystack string in %s on line %d
58bool(false)
59ASCII String:
60mb_strrpos:
61
62Warning: mb_strrpos(): Offset is greater than the length of haystack string in %s on line %d
63bool(false)
64strrpos:
65
66Warning: strrpos(): Offset is greater than the length of haystack string in %s on line %d
67bool(false)
68
69-- Offset is -13 --
70Multibyte String:
71bool(false)
72ASCII String:
73mb_strrpos:
74bool(false)
75strrpos:
76bool(false)
77
78-- Offset is -12 --
79Multibyte String:
80int(9)
81ASCII String:
82mb_strrpos:
83int(9)
84strrpos:
85int(9)
86