summaryrefslogtreecommitdiff
path: root/ext/mbstring/tests/mb_ereg_variation6.phpt
blob: 42bbbaf8cc78937fd2a1cf5fd0b802dabd7d72ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
--TEST--
Test mb_ereg() function : usage variations - match special characters
--SKIPIF--
<?php
extension_loaded('mbstring') or die('skip');
function_exists('mb_ereg') or die("skip mb_ereg() is not available in this build");
?>
--FILE--
<?php
/* Prototype  : int mb_ereg(string $pattern, string $string [, array $registers])
 * Description: Regular expression match for multibyte string 
 * Source code: ext/mbstring/php_mbregex.c
 */

/*
 * Test how mb_ereg() matches special characters for $pattern
 */

echo "*** Testing mb_ereg() : usage variations ***\n";

if(mb_regex_encoding('utf-8') == true) {
	echo "Regex encoding set to utf-8\n";
} else {
	echo "Could not set regex encoding to utf-8\n";
}

$regex_char = array ('\w+', '\W+', '\s+', '\S+', '\d+', '\D+', '\b', '\B');

$string_ascii = 'This is an English string. 0123456789.';
$string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');

foreach ($regex_char as $char) {
	echo "\n--** Pattern is: $char **--\n";
	if (@$regs_ascii || @$regs_mb) {
		$regs_ascii = null;
		$regs_mb = null;
	}
	echo "-- ASCII String: --\n";
	var_dump(mb_ereg($char, $string_ascii, $regs_ascii));
	var_dump($regs_ascii);

	echo "-- Multibyte String: --\n";
	var_dump(mb_ereg($char, $string_mb, $regs_mb));
	base64_encode_var_dump($regs_mb);

}

/**
 * replicate a var dump of an array but outputted string values are base64 encoded
 *
 * @param array $regs
 */
function base64_encode_var_dump($regs) {
	if ($regs) {
		echo "array(" . count($regs) . ") {\n";
		foreach ($regs as $key => $value) {
			echo "  [$key]=>\n  ";
			if (is_string($value)) {
				var_dump(base64_encode($value));
			} else {
				var_dump($value);
			}
		}
		echo "}\n";
	} else {
		echo "NULL\n";
	}
}

echo "Done";

?>
--EXPECTF--
*** Testing mb_ereg() : usage variations ***
Regex encoding set to utf-8

--** Pattern is: \w+ **--
-- ASCII String: --
int(4)
array(1) {
  [0]=>
  string(4) "This"
}
-- Multibyte String: --
int(27)
array(1) {
  [0]=>
  string(36) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ"
}

--** Pattern is: \W+ **--
-- ASCII String: --
int(1)
array(1) {
  [0]=>
  string(1) " "
}
-- Multibyte String: --
int(3)
array(1) {
  [0]=>
  string(4) "44CC"
}

--** Pattern is: \s+ **--
-- ASCII String: --
int(1)
array(1) {
  [0]=>
  string(1) " "
}
-- Multibyte String: --
bool(false)
NULL

--** Pattern is: \S+ **--
-- ASCII String: --
int(4)
array(1) {
  [0]=>
  string(4) "This"
}
-- Multibyte String: --
int(53)
array(1) {
  [0]=>
  string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII="
}

--** Pattern is: \d+ **--
-- ASCII String: --
int(10)
array(1) {
  [0]=>
  string(10) "0123456789"
}
-- Multibyte String: --
int(20)
array(1) {
  [0]=>
  string(28) "MDEyMzTvvJXvvJbvvJfvvJjvvJk="
}

--** Pattern is: \D+ **--
-- ASCII String: --
int(27)
array(1) {
  [0]=>
  string(27) "This is an English string. "
}
-- Multibyte String: --
int(30)
array(1) {
  [0]=>
  string(40) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC"
}

--** Pattern is: \b **--
-- ASCII String: --
int(1)
array(1) {
  [0]=>
  bool(false)
}
-- Multibyte String: --
int(1)
array(1) {
  [0]=>
  bool(false)
}

--** Pattern is: \B **--
-- ASCII String: --
int(1)
array(1) {
  [0]=>
  bool(false)
}
-- Multibyte String: --
int(1)
array(1) {
  [0]=>
  bool(false)
}
Done
--UEXPECTF--
*** Testing mb_ereg() : usage variations ***
Regex encoding set to utf-8

--** Pattern is: \w+ **--
-- ASCII String: --
int(4)
array(1) {
  [0]=>
  string(4) "This"
}
-- Multibyte String: --
int(27)
array(1) {
  [0]=>
  string(36) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ"
}

--** Pattern is: \W+ **--
-- ASCII String: --
int(1)
array(1) {
  [0]=>
  string(1) " "
}
-- Multibyte String: --
int(3)
array(1) {
  [0]=>
  string(4) "44CC"
}

--** Pattern is: \s+ **--
-- ASCII String: --
int(1)
array(1) {
  [0]=>
  string(1) " "
}
-- Multibyte String: --
bool(false)
NULL

--** Pattern is: \S+ **--
-- ASCII String: --
int(4)
array(1) {
  [0]=>
  string(4) "This"
}
-- Multibyte String: --
int(53)
array(1) {
  [0]=>
  string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII="
}

--** Pattern is: \d+ **--
-- ASCII String: --
int(10)
array(1) {
  [0]=>
  string(10) "0123456789"
}
-- Multibyte String: --
int(20)
array(1) {
  [0]=>
  string(28) "MDEyMzTvvJXvvJbvvJfvvJjvvJk="
}

--** Pattern is: \D+ **--
-- ASCII String: --
int(27)
array(1) {
  [0]=>
  string(27) "This is an English string. "
}
-- Multibyte String: --
int(30)
array(1) {
  [0]=>
  string(40) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC"
}

--** Pattern is: \b **--
-- ASCII String: --
int(1)
array(1) {
  [0]=>
  bool(false)
}
-- Multibyte String: --
int(1)
array(1) {
  [0]=>
  bool(false)
}

--** Pattern is: \B **--
-- ASCII String: --
int(1)
array(1) {
  [0]=>
  bool(false)
}
-- Multibyte String: --
int(1)
array(1) {
  [0]=>
  bool(false)
}
Done