1--TEST--
2Test mb_ereg() function : basic functionality
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 basic functionality of mb_ereg
17 */
18
19echo "*** Testing mb_ereg() : basic functionality ***\n";
20
21if(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
34echo "\n**-- ASCII String --**\n";
35echo "-- Without \$regs argument--\n";
36var_dump(mb_ereg($regex_ascii1, $string_ascii));
37var_dump(mb_ereg($regex_ascii2, $string_ascii));
38echo "--With \$regs argument --\n";
39var_dump(mb_ereg($regex_ascii1, $string_ascii, $regs_ascii1));
40base64_encode_var_dump($regs_ascii1);
41var_dump(mb_ereg($regex_ascii2, $string_ascii, $regs_ascii2));
42base64_encode_var_dump($regs_ascii2);
43
44echo "\n**-- Multibyte String --**\n";
45echo "-- Without \$regs argument --\n";
46var_dump(mb_ereg($regex_mb1, $string_mb));
47var_dump(mb_ereg($regex_mb2, $string_mb));
48echo "-- With \$regs argument --\n";
49var_dump(mb_ereg($regex_mb1, $string_mb, $regs_mb1));
50base64_encode_var_dump($regs_mb1);
51var_dump(mb_ereg($regex_mb2, $string_mb, $regs_mb2));
52var_dump($regs_mb2);
53
54echo "Done";
55
56/**
57 * replicate a var dump of an array but outputted string values are base64 encoded
58 *
59 * @param array $regs
60 */
61function 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 ***
81Regex encoding set to utf-8
82
83**-- ASCII String --**
84-- Without $regs argument--
85int(1)
86int(1)
87--With $regs argument --
88int(36)
89array(2) {
90  [0]=>
91  string(48) "VGhpcyBpcyBhbiBFbmdsaXNoIHN0cmluZy4gMDEyMzQ1Njc4"
92  [1]=>
93  string(24) "VGhpcyBpcyBhbiBFbmdsaXM="
94}
95int(17)
96array(1) {
97  [0]=>
98  string(24) "VGhpcyBpcyBhbiBFbmdsaXM="
99}
100
101**-- Multibyte String --**
102-- Without $regs argument --
103int(1)
104bool(false)
105-- With $regs argument --
106int(35)
107array(3) {
108  [0]=>
109  string(48) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzQ="
110  [1]=>
111  string(12) "5pel5pys6Kqe"
112  [2]=>
113  string(8) "MTIzNA=="
114}
115bool(false)
116NULL
117Done