1--TEST--
2Test mb_strrchr() function : basic functionality
3--SKIPIF--
4<?php
5extension_loaded('mbstring') or die('skip');
6function_exists('mb_strrchr') or die("skip mb_strrchr() is not available in this build");
7?>
8--FILE--
9<?php
10/* Prototype  : string mb_strrchr(string haystack, string needle[, bool part[, string encoding]])
11 * Description: Finds the last occurrence of a character in a string within another
12 * Source code: ext/mbstring/mbstring.c
13 * Alias to functions:
14 */
15
16echo "*** Testing mb_strrchr() : basic functionality ***\n";
17
18mb_internal_encoding('UTF-8');
19
20$string_ascii = b'abc def';
21//Japanese string in UTF-8
22$string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
23
24echo "\n-- ASCII string: needle exists --\n";
25var_dump(bin2hex(mb_strrchr($string_ascii, b'd', false, 'ISO-8859-1')));
26var_dump(bin2hex(mb_strrchr($string_ascii, b'd')));
27var_dump(bin2hex(mb_strrchr($string_ascii, b'd', true)));
28
29
30echo "\n-- ASCII string: needle doesn't exist --\n";
31var_dump(mb_strrchr($string_ascii, b'123'));
32
33echo "\n-- Multibyte string: needle exists --\n";
34$needle1 = base64_decode('5pel5pys6Kqe');
35var_dump(bin2hex(mb_strrchr($string_mb, $needle1)));
36var_dump(bin2hex(mb_strrchr($string_mb, $needle1, false, 'utf-8')));
37var_dump(bin2hex(mb_strrchr($string_mb, $needle1, true)));
38
39
40echo "\n-- Multibyte string: needle doesn't exist --\n";
41$needle2 = base64_decode('44GT44KT44Gr44Gh44Gv44CB5LiW55WM');
42var_dump(mb_strrchr($string_mb, $needle2));
43
44?>
45===DONE===
46--EXPECT--
47*** Testing mb_strrchr() : basic functionality ***
48
49-- ASCII string: needle exists --
50string(6) "646566"
51string(6) "646566"
52string(8) "61626320"
53
54-- ASCII string: needle doesn't exist --
55bool(false)
56
57-- Multibyte string: needle exists --
58string(106) "e697a5e69cace8aa9ee38386e382ade382b9e38388e381a7e38199e380823031323334efbc95efbc96efbc97efbc98efbc99e38082"
59string(106) "e697a5e69cace8aa9ee38386e382ade382b9e38388e381a7e38199e380823031323334efbc95efbc96efbc97efbc98efbc99e38082"
60string(0) ""
61
62-- Multibyte string: needle doesn't exist --
63bool(false)
64===DONE===