1--TEST--
2Test mb_stristr() function : usage variation - multiple needles
3--SKIPIF--
4<?php
5extension_loaded('mbstring') or die('skip');
6function_exists('mb_stristr') or die("skip mb_stristr() is not available in this build");
7?>
8--FILE--
9<?php
10/* Prototype  : string mb_stristr(string haystack, string needle[, bool part[, string encoding]])
11 * Description: Finds first occurrence of a string within another, case insensitive
12 * Source code: ext/mbstring/mbstring.c
13 * Alias to functions:
14 */
15
16echo "*** Testing mb_stristr() : basic functionality ***\n";
17
18mb_internal_encoding('UTF-8');
19
20//ascii mixed case, multiple needles
21$string_ascii = b'abcDef zBcDyx';
22$needle_ascii_upper = b"BCD";
23$needle_ascii_mixed = b"bCd";
24$needle_ascii_lower = b"bcd";
25
26//Greek string in mixed case UTF-8 with multiple needles
27$string_mb = base64_decode('zrrOu868zr3Ovs6fzqDOoSDOus67zpzOnc6+zr/OoA==');
28$needle_mb_upper = base64_decode('zpzOnc6ezp8=');
29$needle_mb_lower = base64_decode('zrzOvc6+zr8=');
30$needle_mb_mixed = base64_decode('zpzOnc6+zr8=');
31
32echo "\n-- ASCII string: needle exists --\n";
33var_dump(bin2hex(mb_stristr($string_ascii, $needle_ascii_upper, false)));
34var_dump(bin2hex(mb_stristr($string_ascii, $needle_ascii_upper, true)));
35var_dump(bin2hex(mb_stristr($string_ascii, $needle_ascii_lower, false)));
36var_dump(bin2hex(mb_stristr($string_ascii, $needle_ascii_lower, true)));
37var_dump(bin2hex(mb_stristr($string_ascii, $needle_ascii_mixed, false)));
38var_dump(bin2hex(mb_stristr($string_ascii, $needle_ascii_mixed, true)));
39
40
41echo "\n-- Multibyte string: needle exists --\n";
42var_dump(bin2hex(mb_stristr($string_mb, $needle_mb_upper, false)));
43var_dump(bin2hex(mb_stristr($string_mb, $needle_mb_upper, true)));
44var_dump(bin2hex(mb_stristr($string_mb, $needle_mb_lower, false)));
45var_dump(bin2hex(mb_stristr($string_mb, $needle_mb_lower, true)));
46var_dump(bin2hex(mb_stristr($string_mb, $needle_mb_mixed, false)));
47var_dump(bin2hex(mb_stristr($string_mb, $needle_mb_mixed, true)));
48
49?>
50===DONE===
51--EXPECT--
52*** Testing mb_stristr() : basic functionality ***
53
54-- ASCII string: needle exists --
55string(24) "6263446566207a4263447978"
56string(2) "61"
57string(24) "6263446566207a4263447978"
58string(2) "61"
59string(24) "6263446566207a4263447978"
60string(2) "61"
61
62-- Multibyte string: needle exists --
63string(54) "cebccebdcebece9fcea0cea120cebacebbce9cce9dcebecebfcea0"
64string(8) "cebacebb"
65string(54) "cebccebdcebece9fcea0cea120cebacebbce9cce9dcebecebfcea0"
66string(8) "cebacebb"
67string(54) "cebccebdcebece9fcea0cea120cebacebbce9cce9dcebecebfcea0"
68string(8) "cebacebb"
69===DONE===
70