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/*
11 * Test basic functionality of mb_ereg
12 */
13
14echo "*** Testing mb_ereg() : basic functionality ***\n";
15
16if(mb_regex_encoding('utf-8') == true) {
17    echo "Regex encoding set to utf-8\n";
18} else {
19    echo "Could not set regex encoding to utf-8\n";
20}
21$string_ascii = 'This is an English string. 0123456789.';
22$regex_ascii1 = '(.*is)+.*\.[[:blank:]][0-9]{9}';
23$regex_ascii2 = '.*is+';
24
25$string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
26$regex_mb1 = base64_decode('KOaXpeacrOiqnikuKj8oWzEtOV0rKQ==');
27$regex_mb2 = base64_decode('5LiW55WM');
28
29echo "\n**-- ASCII String --**\n";
30echo "-- Without \$regs argument--\n";
31var_dump(mb_ereg($regex_ascii1, $string_ascii));
32var_dump(mb_ereg($regex_ascii2, $string_ascii));
33echo "--With \$regs argument --\n";
34var_dump(mb_ereg($regex_ascii1, $string_ascii, $regs_ascii1));
35base64_encode_var_dump($regs_ascii1);
36var_dump(mb_ereg($regex_ascii2, $string_ascii, $regs_ascii2));
37base64_encode_var_dump($regs_ascii2);
38
39echo "\n**-- Multibyte String --**\n";
40echo "-- Without \$regs argument --\n";
41var_dump(mb_ereg($regex_mb1, $string_mb));
42var_dump(mb_ereg($regex_mb2, $string_mb));
43echo "-- With \$regs argument --\n";
44var_dump(mb_ereg($regex_mb1, $string_mb, $regs_mb1));
45base64_encode_var_dump($regs_mb1);
46var_dump(mb_ereg($regex_mb2, $string_mb, $regs_mb2));
47var_dump($regs_mb2);
48
49echo "Done";
50
51/**
52 * replicate a var dump of an array but outputted string values are base64 encoded
53 *
54 * @param array $regs
55 */
56function base64_encode_var_dump($regs) {
57    if ($regs) {
58        echo "array(" . count($regs) . ") {\n";
59        foreach ($regs as $key => $value) {
60            echo "  [$key]=>\n  ";
61            if (is_string($value)) {
62                var_dump(base64_encode($value));
63            } else {
64                var_dump($value);
65            }
66        }
67        echo "}\n";
68    } else {
69        echo "NULL\n";
70    }
71}
72?>
73--EXPECT--
74*** Testing mb_ereg() : basic functionality ***
75Regex encoding set to utf-8
76
77**-- ASCII String --**
78-- Without $regs argument--
79bool(true)
80bool(true)
81--With $regs argument --
82bool(true)
83array(2) {
84  [0]=>
85  string(48) "VGhpcyBpcyBhbiBFbmdsaXNoIHN0cmluZy4gMDEyMzQ1Njc4"
86  [1]=>
87  string(24) "VGhpcyBpcyBhbiBFbmdsaXM="
88}
89bool(true)
90array(1) {
91  [0]=>
92  string(24) "VGhpcyBpcyBhbiBFbmdsaXM="
93}
94
95**-- Multibyte String --**
96-- Without $regs argument --
97bool(true)
98bool(false)
99-- With $regs argument --
100bool(true)
101array(3) {
102  [0]=>
103  string(48) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzQ="
104  [1]=>
105  string(12) "5pel5pys6Kqe"
106  [2]=>
107  string(8) "MTIzNA=="
108}
109bool(false)
110array(0) {
111}
112Done
113