1--TEST--
2Test mb_strrichr() function : basic functionality
3--SKIPIF--
4<?php
5extension_loaded('mbstring') or die('skip');
6function_exists('mb_strrichr') or die("skip mb_strrichr() is not available in this build");
7?>
8--FILE--
9<?php
10/* Prototype  : string mb_strrichr(string haystack, string needle[, bool part[, string encoding]])
11 * Description: Finds the last occurrence of a character in a string within another, case insensitive
12 * Source code: ext/mbstring/mbstring.c
13 * Alias to functions:
14 */
15
16echo "*** Testing mb_strrichr() : basic functionality ***\n";
17
18mb_internal_encoding('UTF-8');
19
20$string_ascii = b'abcdef';
21$needle_ascii_upper = b"BCD";
22$needle_ascii_mixed = b"bCd";
23$needle_ascii_lower = b"bcd";
24
25//Greek string in lower case UTF-8
26$string_mb = base64_decode('zrHOss6zzrTOtc62zrfOuM65zrrOu868zr3Ovs6/z4DPgc+Dz4TPhc+Gz4fPiM+J');
27$needle_mb_upper = base64_decode('zpzOnc6ezp8=');
28$needle_mb_lower = base64_decode('zrzOvc6+zr8=');
29$needle_mb_mixed = base64_decode('zpzOnc6+zr8=');
30
31echo "\n-- ASCII string: needle exists --\n";
32var_dump(bin2hex(mb_strrichr($string_ascii, $needle_ascii_upper, false, 'ISO-8859-1')));
33var_dump(bin2hex(mb_strrichr($string_ascii, $needle_ascii_lower)));
34var_dump(bin2hex(mb_strrichr($string_ascii, $needle_ascii_mixed, true)));
35
36
37echo "\n-- ASCII string: needle doesn't exist --\n";
38var_dump(mb_strrichr($string_ascii, b'123'));
39
40echo "\n-- Multibyte string: needle exists --\n";
41var_dump(bin2hex(mb_strrichr($string_mb, $needle_mb_upper)));
42var_dump(bin2hex(mb_strrichr($string_mb, $needle_mb_lower, false, 'utf-8')));
43var_dump(bin2hex(mb_strrichr($string_mb, $needle_mb_mixed, true)));
44
45
46echo "\n-- Multibyte string: needle doesn't exist --\n";
47$needle2 = base64_decode('zrzOvs6/');
48var_dump(mb_strrichr($string_mb, $needle2));
49
50?>
51===DONE===
52--EXPECT--
53*** Testing mb_strrichr() : basic functionality ***
54
55-- ASCII string: needle exists --
56string(10) "6263646566"
57string(10) "6263646566"
58string(2) "61"
59
60-- ASCII string: needle doesn't exist --
61bool(false)
62
63-- Multibyte string: needle exists --
64string(52) "cebccebdcebecebfcf80cf81cf83cf84cf85cf86cf87cf88cf89"
65string(52) "cebccebdcebecebfcf80cf81cf83cf84cf85cf86cf87cf88cf89"
66string(44) "ceb1ceb2ceb3ceb4ceb5ceb6ceb7ceb8ceb9cebacebb"
67
68-- Multibyte string: needle doesn't exist --
69bool(false)
70===DONE===
71