1--TEST--
2Test mb_ereg() function : usage variations - Test anchors in regex
3--EXTENSIONS--
4mbstring
5--SKIPIF--
6<?php
7function_exists('mb_ereg') or die("skip mb_ereg() is not available in this build");
8?>
9--FILE--
10<?php
11/*
12 * Test mb_ereg with anchors (start and end of string) in $pattern
13 */
14
15echo "*** Testing mb_ereg() : usage variations ***\n";
16
17mb_regex_encoding('utf-8');
18
19$string_ascii = 'This is an English string. 0123456789.';
20$string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
21
22$regex = '^.*?[[:blank:]]?[[:punct:][:digit:]]+\.?$';
23
24echo "\nASCII String without \$regs arg:\t\t";
25var_dump(mb_ereg($regex, $string_ascii));
26echo "ASCII String with \$regs arg:\n";
27var_dump(mb_ereg($regex, $string_ascii, $regs_ascii));
28base64_encode_var_dump($regs_ascii);
29
30echo "\nMultibyte String without \$regs arg:\t";
31var_dump(mb_ereg($regex, $string_mb));
32echo "Multubyte String with \$regs arg:\n";
33var_dump(mb_ereg($regex, $string_mb, $regs_mb));
34base64_encode_var_dump($regs_mb);
35
36echo "Done";
37
38/**
39 * replicate a var dump of an array but outputted string values are base64 encoded
40 *
41 * @param array $regs
42 */
43function base64_encode_var_dump($regs) {
44    if ($regs) {
45        echo "array(" . count($regs) . ") {\n";
46        foreach ($regs as $key => $value) {
47            echo "  [$key]=>\n  ";
48            if (is_string($value)) {
49                var_dump(base64_encode($value));
50            } else {
51                var_dump($value);
52            }
53        }
54        echo "}\n";
55    } else {
56        echo "NULL\n";
57    }
58}
59?>
60--EXPECT--
61*** Testing mb_ereg() : usage variations ***
62
63ASCII String without $regs arg:		bool(true)
64ASCII String with $regs arg:
65bool(true)
66array(1) {
67  [0]=>
68  string(52) "VGhpcyBpcyBhbiBFbmdsaXNoIHN0cmluZy4gMDEyMzQ1Njc4OS4="
69}
70
71Multibyte String without $regs arg:	bool(true)
72Multubyte String with $regs arg:
73bool(true)
74array(1) {
75  [0]=>
76  string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII="
77}
78Done
79