1--TEST--
2Test mb_strstr() function : basic functionality
3--EXTENSIONS--
4mbstring
5--FILE--
6<?php
7echo "*** Testing mb_strstr() : basic functionality ***\n";
8
9mb_internal_encoding('UTF-8');
10
11$string_ascii = 'abc def';
12//Japanese string in UTF-8
13$string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
14
15echo "\n-- ASCII string: needle exists --\n";
16var_dump(bin2hex(mb_strstr($string_ascii, 'd', false, 'ISO-8859-1')));
17var_dump(bin2hex(mb_strstr($string_ascii, 'd')));
18var_dump(bin2hex(mb_strstr($string_ascii, 'd', true)));
19
20
21echo "\n-- ASCII string: needle doesn't exist --\n";
22var_dump(mb_strstr($string_ascii, '123'));
23
24echo "\n-- Multibyte string: needle exists --\n";
25$needle1 = base64_decode('5pel5pys6Kqe');
26var_dump(bin2hex(mb_strstr($string_mb, $needle1)));
27var_dump(bin2hex(mb_strstr($string_mb, $needle1, false, 'utf-8')));
28var_dump(bin2hex(mb_strstr($string_mb, $needle1, true)));
29
30
31echo "\n-- Multibyte string: needle doesn't exist --\n";
32$needle2 = base64_decode('44GT44KT44Gr44Gh44Gv44CB5LiW55WM');
33var_dump(mb_strstr($string_mb, $needle2));
34
35?>
36--EXPECT--
37*** Testing mb_strstr() : basic functionality ***
38
39-- ASCII string: needle exists --
40string(6) "646566"
41string(6) "646566"
42string(8) "61626320"
43
44-- ASCII string: needle doesn't exist --
45bool(false)
46
47-- Multibyte string: needle exists --
48string(106) "e697a5e69cace8aa9ee38386e382ade382b9e38388e381a7e38199e380823031323334efbc95efbc96efbc97efbc98efbc99e38082"
49string(106) "e697a5e69cace8aa9ee38386e382ade382b9e38388e381a7e38199e380823031323334efbc95efbc96efbc97efbc98efbc99e38082"
50string(0) ""
51
52-- Multibyte string: needle doesn't exist --
53bool(false)
54