xref: /PHP-7.2/ext/mbstring/tests/bug43841.phpt (revision f1d7e3ca)
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('This is na English ta', 'a', $i));
32	echo "strrpos:\n";
33	var_dump(strrpos('This is na English ta', 'a', $i));
34}
35?>
36--EXPECTF--
37-- Offset is -25 --
38Multibyte String:
39
40Warning: mb_strrpos(): Offset is greater than the length of haystack string in %s on line %d
41bool(false)
42ASCII String:
43mb_strrpos:
44
45Warning: mb_strrpos(): Offset is greater than the length of haystack string in %s on line %d
46bool(false)
47strrpos:
48
49Warning: strrpos(): Offset is greater than the length of haystack string in %s on line %d
50bool(false)
51
52-- Offset is -24 --
53Multibyte String:
54
55Warning: mb_strrpos(): Offset is greater than the length of haystack string in %s on line %d
56bool(false)
57ASCII String:
58mb_strrpos:
59
60Warning: mb_strrpos(): Offset is greater than the length of haystack string in %s on line %d
61bool(false)
62strrpos:
63
64Warning: strrpos(): Offset is greater than the length of haystack string in %s on line %d
65bool(false)
66
67-- Offset is -13 --
68Multibyte String:
69bool(false)
70ASCII String:
71mb_strrpos:
72bool(false)
73strrpos:
74bool(false)
75
76-- Offset is -12 --
77Multibyte String:
78int(9)
79ASCII String:
80mb_strrpos:
81int(9)
82strrpos:
83int(9)
84