Annotation of embedaddon/php/ext/mbstring/tests/mb_ereg_basic.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test mb_ereg() function : basic functionality
3: --SKIPIF--
4: <?php
5: extension_loaded('mbstring') or die('skip');
6: function_exists('mb_ereg') or die("skip mb_ereg() is not available in this build");
7: ?>
8: --FILE--
9: <?php
10: /* Prototype : int mb_ereg(string $pattern, string $string [, array $registers])
11: * Description: Regular expression match for multibyte string
12: * Source code: ext/mbstring/php_mbregex.c
13: */
14:
15: /*
16: * Test basic functionality of mb_ereg
17: */
18:
19: echo "*** Testing mb_ereg() : basic functionality ***\n";
20:
21: if(mb_regex_encoding('utf-8') == true) {
22: echo "Regex encoding set to utf-8\n";
23: } else {
24: echo "Could not set regex encoding to utf-8\n";
25: }
26: $string_ascii = b'This is an English string. 0123456789.';
27: $regex_ascii1 = b'(.*is)+.*\.[[:blank:]][0-9]{9}';
28: $regex_ascii2 = b'.*is+';
29:
30: $string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
31: $regex_mb1 = base64_decode('KOaXpeacrOiqnikuKj8oWzEtOV0rKQ==');
32: $regex_mb2 = base64_decode('5LiW55WM');
33:
34: echo "\n**-- ASCII String --**\n";
35: echo "-- Without \$regs argument--\n";
36: var_dump(mb_ereg($regex_ascii1, $string_ascii));
37: var_dump(mb_ereg($regex_ascii2, $string_ascii));
38: echo "--With \$regs argument --\n";
39: var_dump(mb_ereg($regex_ascii1, $string_ascii, $regs_ascii1));
40: base64_encode_var_dump($regs_ascii1);
41: var_dump(mb_ereg($regex_ascii2, $string_ascii, $regs_ascii2));
42: base64_encode_var_dump($regs_ascii2);
43:
44: echo "\n**-- Multibyte String --**\n";
45: echo "-- Without \$regs argument --\n";
46: var_dump(mb_ereg($regex_mb1, $string_mb));
47: var_dump(mb_ereg($regex_mb2, $string_mb));
48: echo "-- With \$regs argument --\n";
49: var_dump(mb_ereg($regex_mb1, $string_mb, $regs_mb1));
50: base64_encode_var_dump($regs_mb1);
51: var_dump(mb_ereg($regex_mb2, $string_mb, $regs_mb2));
52: var_dump($regs_mb2);
53:
54: echo "Done";
55:
56: /**
57: * replicate a var dump of an array but outputted string values are base64 encoded
58: *
59: * @param array $regs
60: */
61: function base64_encode_var_dump($regs) {
62: if ($regs) {
63: echo "array(" . count($regs) . ") {\n";
64: foreach ($regs as $key => $value) {
65: echo " [$key]=>\n ";
66: if (is_string($value)) {
67: var_dump(base64_encode($value));
68: } else {
69: var_dump($value);
70: }
71: }
72: echo "}\n";
73: } else {
74: echo "NULL\n";
75: }
76: }
77: ?>
78:
79: --EXPECT--
80: *** Testing mb_ereg() : basic functionality ***
81: Regex encoding set to utf-8
82:
83: **-- ASCII String --**
84: -- Without $regs argument--
85: int(1)
86: int(1)
87: --With $regs argument --
88: int(36)
89: array(2) {
90: [0]=>
91: string(48) "VGhpcyBpcyBhbiBFbmdsaXNoIHN0cmluZy4gMDEyMzQ1Njc4"
92: [1]=>
93: string(24) "VGhpcyBpcyBhbiBFbmdsaXM="
94: }
95: int(17)
96: array(1) {
97: [0]=>
98: string(24) "VGhpcyBpcyBhbiBFbmdsaXM="
99: }
100:
101: **-- Multibyte String --**
102: -- Without $regs argument --
103: int(1)
104: bool(false)
105: -- With $regs argument --
106: int(35)
107: array(3) {
108: [0]=>
109: string(48) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzQ="
110: [1]=>
111: string(12) "5pel5pys6Kqe"
112: [2]=>
113: string(8) "MTIzNA=="
114: }
115: bool(false)
116: NULL
117: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>