1--TEST--
2Test mb_strstr() function : basic functionality
3--SKIPIF--
4<?php
5extension_loaded('mbstring') or die('skip');
6function_exists('mb_strstr') or die("skip mb_strstr() is not available in this build");
7?>
8--FILE--
9<?php
10/* Prototype  : string mb_strstr(string haystack, string needle[, bool part[, string encoding]])
11 * Description: Finds first occurrence of a string within another
12 * Source code: ext/mbstring/mbstring.c
13 * Alias to functions:
14 */
15
16echo "*** Testing mb_strstr() : 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_strstr($string_ascii, b'd', false, 'ISO-8859-1')));
26var_dump(bin2hex(mb_strstr($string_ascii, b'd')));
27var_dump(bin2hex(mb_strstr($string_ascii, b'd', true)));
28
29
30echo "\n-- ASCII string: needle doesn't exist --\n";
31var_dump(mb_strstr($string_ascii, b'123'));
32
33echo "\n-- Multibyte string: needle exists --\n";
34$needle1 = base64_decode('5pel5pys6Kqe');
35var_dump(bin2hex(mb_strstr($string_mb, $needle1)));
36var_dump(bin2hex(mb_strstr($string_mb, $needle1, false, 'utf-8')));
37var_dump(bin2hex(mb_strstr($string_mb, $needle1, true)));
38
39
40echo "\n-- Multibyte string: needle doesn't exist --\n";
41$needle2 = base64_decode('44GT44KT44Gr44Gh44Gv44CB5LiW55WM');
42var_dump(mb_strstr($string_mb, $needle2));
43
44?>
45===DONE===
46--EXPECT--
47*** Testing mb_strstr() : 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===
65