Annotation of embedaddon/php/ext/mbstring/tests/mb_ereg_variation4.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test mb_ereg() function : usage variations - pass different character classes as pattern for multibyte string
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 how character classes match a multibyte string
17: */
18:
19: echo "*** Testing mb_ereg() : usage variations ***\n";
20:
21: mb_regex_encoding('utf-8');
22:
23: //contains japanese characters, ASCII digits and different, UTF-8 encoded digits
24: $string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
25:
26: $character_classes = array (b'[[:alnum:]]+', /*1*/
27: b'[[:alpha:]]+',
28: b'[[:ascii:]]+',
29: b'[[:blank:]]+',
30: b'[[:cntrl:]]+',/*5*/
31: b'[[:digit:]]+',
32: b'[[:graph:]]+',
33: b'[[:lower:]]+',
34: b'[[:print:]]+',
35: b'[[:punct:]]+', /*10*/
36: b'[[:space:]]+',
37: b'[[:upper:]]+',
38: b'[[:xdigit:]]+'); /*13*/
39:
40: $iterator = 1;
41: foreach ($character_classes as $pattern) {
42: if (is_array(@$regs)) {
43: $regs = null;
44: }
45: echo "\n-- Iteration $iterator --\n";
46: var_dump(mb_ereg($pattern, $string_mb, $regs));
47: if ($regs) {
48: base64_encode_var_dump($regs);
49: }
50: $iterator++;
51: }
52: /**
53: * replicate a var dump of an array but outputted string values are base64 encoded
54: *
55: * @param array $regs
56: */
57: function base64_encode_var_dump($regs) {
58: if ($regs) {
59: echo "array(" . count($regs) . ") {\n";
60: foreach ($regs as $key => $value) {
61: echo " [$key]=>\n ";
62: if (is_string($value)) {
63: var_dump(base64_encode($value));
64: } else {
65: var_dump($value);
66: }
67: }
68: echo "}\n";
69: } else {
70: echo "NULL\n";
71: }
72: }
73: echo "Done";
74:
75: ?>
76: --EXPECTF--
77: *** Testing mb_ereg() : usage variations ***
78:
79: -- Iteration 1 --
80: int(47)
81: array(1) {
82: [0]=>
83: string(64) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZMDEyMzTvvJXvvJbvvJfvvJjvvJk="
84: }
85:
86: -- Iteration 2 --
87: int(27)
88: array(1) {
89: [0]=>
90: string(36) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ"
91: }
92:
93: -- Iteration 3 --
94: int(5)
95: array(1) {
96: [0]=>
97: string(8) "MDEyMzQ="
98: }
99:
100: -- Iteration 4 --
101: bool(false)
102:
103: -- Iteration 5 --
104: bool(false)
105:
106: -- Iteration 6 --
107: int(20)
108: array(1) {
109: [0]=>
110: string(28) "MDEyMzTvvJXvvJbvvJfvvJjvvJk="
111: }
112:
113: -- Iteration 7 --
114: int(50)
115: array(1) {
116: [0]=>
117: string(68) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII="
118: }
119:
120: -- Iteration 8 --
121: bool(false)
122:
123: -- Iteration 9 --
124: int(50)
125: array(1) {
126: [0]=>
127: string(68) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII="
128: }
129:
130: -- Iteration 10 --
131: int(3)
132: array(1) {
133: [0]=>
134: string(4) "44CC"
135: }
136:
137: -- Iteration 11 --
138: bool(false)
139:
140: -- Iteration 12 --
141: bool(false)
142:
143: -- Iteration 13 --
144: int(5)
145: array(1) {
146: [0]=>
147: string(8) "MDEyMzQ="
148: }
149: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>