1--TEST--
2Test mb_ereg() function : usage variations - pass different character classes to see they match correctly
3--SKIPIF--
4<?php
5extension_loaded('mbstring') or die('skip');
6function_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 that mb_ereg can match correctly when passed different character classes.
17 */
18
19echo "*** Testing mb_ereg() : variation ***\n";
20
21
22mb_regex_encoding('utf-8'); // have to set otherwise won't match $mb properly
23$mb = base64_decode('5pel5pys6Kqe');
24$character_classes = array (b'aB1'    => b'[[:alnum:]]+', /*1*/
25                            b'aBcD'   => b'[[:alpha:]]+',
26                            b'ab/='   => b'[[:ascii:]]+',
27                            b" \t"    => b'[[:blank:]]+',
28                            b'234'    => b'[[:digit:]]+', /*5*/
29                            "$mb"    => b'[[:graph:]]+',
30                            b'fjds'   => b'[[:lower:]]+',
31                            b"$mb\t"  => b'[[:print:]]+',
32                            b'.!"*@'  => b'[[:punct:]]+',
33                            b"\t"     => b'[[:space:]]+', /*10*/
34                            b'IDSJV'  => b'[[:upper:]]+',
35                            b'3b5D'   => b'[[:xdigit:]]+'); /*12*/
36
37$iterator = 1;
38foreach($character_classes as $string => $pattern) {
39	if (is_array(@$regs)) {
40		$regs = null;
41	}
42	// make sure any multibyte output is in base 64
43	echo "\n-- Iteration $iterator --\n";
44	var_dump(mb_ereg($pattern, $string, $regs));
45	base64_encode_var_dump($regs);
46	$iterator++;
47}
48/**
49 * replicate a var dump of an array but outputted string values are base64 encoded
50 *
51 * @param array $regs
52 */
53function base64_encode_var_dump($regs) {
54	if ($regs) {
55		echo "array(" . count($regs) . ") {\n";
56		foreach ($regs as $key => $value) {
57			echo "  [$key]=>\n  ";
58			if (is_string($value)) {
59				var_dump(base64_encode($value));
60			} else {
61				var_dump($value);
62			}
63		}
64		echo "}\n";
65	} else {
66		echo "NULL\n";
67	}
68}
69
70echo "Done";
71?>
72--EXPECT--
73*** Testing mb_ereg() : variation ***
74
75-- Iteration 1 --
76int(3)
77array(1) {
78  [0]=>
79  string(4) "YUIx"
80}
81
82-- Iteration 2 --
83int(4)
84array(1) {
85  [0]=>
86  string(8) "YUJjRA=="
87}
88
89-- Iteration 3 --
90int(4)
91array(1) {
92  [0]=>
93  string(8) "YWIvPQ=="
94}
95
96-- Iteration 4 --
97int(2)
98array(1) {
99  [0]=>
100  string(4) "IAk="
101}
102
103-- Iteration 5 --
104int(3)
105array(1) {
106  [0]=>
107  string(4) "MjM0"
108}
109
110-- Iteration 6 --
111int(9)
112array(1) {
113  [0]=>
114  string(12) "5pel5pys6Kqe"
115}
116
117-- Iteration 7 --
118int(4)
119array(1) {
120  [0]=>
121  string(8) "Zmpkcw=="
122}
123
124-- Iteration 8 --
125int(10)
126array(1) {
127  [0]=>
128  string(16) "5pel5pys6KqeCQ=="
129}
130
131-- Iteration 9 --
132int(5)
133array(1) {
134  [0]=>
135  string(8) "LiEiKkA="
136}
137
138-- Iteration 10 --
139int(1)
140array(1) {
141  [0]=>
142  string(4) "CQ=="
143}
144
145-- Iteration 11 --
146int(5)
147array(1) {
148  [0]=>
149  string(8) "SURTSlY="
150}
151
152-- Iteration 12 --
153int(4)
154array(1) {
155  [0]=>
156  string(8) "M2I1RA=="
157}
158Done
159