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