Annotation of embedaddon/php/ext/mbstring/tests/mb_strstr_basic.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test mb_strstr() function : basic functionality
3: --SKIPIF--
4: <?php
5: extension_loaded('mbstring') or die('skip');
6: function_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:
16: echo "*** Testing mb_strstr() : basic functionality ***\n";
17:
18: mb_internal_encoding('UTF-8');
19:
20: $string_ascii = b'abc def';
21: //Japanese string in UTF-8
22: $string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
23:
24: echo "\n-- ASCII string: needle exists --\n";
25: var_dump(bin2hex(mb_strstr($string_ascii, b'd', false, 'ISO-8859-1')));
26: var_dump(bin2hex(mb_strstr($string_ascii, b'd')));
27: var_dump(bin2hex(mb_strstr($string_ascii, b'd', true)));
28:
29:
30: echo "\n-- ASCII string: needle doesn't exist --\n";
31: var_dump(mb_strstr($string_ascii, b'123'));
32:
33: echo "\n-- Multibyte string: needle exists --\n";
34: $needle1 = base64_decode('5pel5pys6Kqe');
35: var_dump(bin2hex(mb_strstr($string_mb, $needle1)));
36: var_dump(bin2hex(mb_strstr($string_mb, $needle1, false, 'utf-8')));
37: var_dump(bin2hex(mb_strstr($string_mb, $needle1, true)));
38:
39:
40: echo "\n-- Multibyte string: needle doesn't exist --\n";
41: $needle2 = base64_decode('44GT44KT44Gr44Gh44Gv44CB5LiW55WM');
42: var_dump(mb_strstr($string_mb, $needle2));
43:
44: ?>
45: ===DONE===
46: --EXPECT--
47: *** Testing mb_strstr() : basic functionality ***
48:
49: -- ASCII string: needle exists --
50: string(6) "646566"
51: string(6) "646566"
52: string(8) "61626320"
53:
54: -- ASCII string: needle doesn't exist --
55: bool(false)
56:
57: -- Multibyte string: needle exists --
58: string(106) "e697a5e69cace8aa9ee38386e382ade382b9e38388e381a7e38199e380823031323334efbc95efbc96efbc97efbc98efbc99e38082"
59: string(106) "e697a5e69cace8aa9ee38386e382ade382b9e38388e381a7e38199e380823031323334efbc95efbc96efbc97efbc98efbc99e38082"
60: string(0) ""
61:
62: -- Multibyte string: needle doesn't exist --
63: bool(false)
64: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>