1--TEST--
2Test mb_ereg() function : usage variations - different regex features in $pattern
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 * Testing the following regular expression features match correctly:
17 * 1. definite quantifiers
18 * 2. Alternation
19 * 3. subpatterns in parentheses
20 */
21
22echo "*** Testing mb_ereg() : usage variations ***\n";
23
24if(mb_regex_encoding('utf-8') == true) {
25	echo "Regex encoding set to utf-8\n";
26} else {
27	echo "Could not set regex encoding to utf-8\n";
28}
29
30$string_ascii = 'This is an English string. 0123456789.';
31$regex_ascii = '([A-Z]\w{1,4}is( [aeiou]|h)) ?.*\.\s[0-9]+(5([6-9][79]){2})[[:punct:]]$';
32var_dump(mb_ereg($regex_ascii, $string_ascii, $regs_ascii));
33base64_encode_var_dump($regs_ascii);
34
35$string_mb = base64_decode('zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868zrXOvc6/LiAwMTIzNDU2Nzg5Lg==');
36$regex_mb = base64_decode("W86RLc6pXShcdysgKSvOtVvOsS3PiVxzXSvOui4qKM+MfM6/KS4qXC5cc1swLTldKyg1KFs2LTldWzc5XSl7Mn0pW1s6cHVuY3Q6XV0k");
37var_dump(mb_ereg($regex_mb, $string_mb, $regs_mb));
38base64_encode_var_dump($regs_mb);
39
40/**
41 * replicate a var dump of an array but outputted string values are base64 encoded
42 *
43 * @param array $regs
44 */
45function base64_encode_var_dump($regs) {
46	if ($regs) {
47		echo "array(" . count($regs) . ") {\n";
48		foreach ($regs as $key => $value) {
49			echo "  [$key]=>\n  ";
50			if (is_string($value)) {
51				var_dump(base64_encode($value));
52			} else {
53				var_dump($value);
54			}
55		}
56		echo "}\n";
57	} else {
58		echo "NULL\n";
59	}
60}
61
62echo "Done";
63
64?>
65--EXPECT--
66*** Testing mb_ereg() : usage variations ***
67Regex encoding set to utf-8
68int(38)
69array(5) {
70  [0]=>
71  string(52) "VGhpcyBpcyBhbiBFbmdsaXNoIHN0cmluZy4gMDEyMzQ1Njc4OS4="
72  [1]=>
73  string(8) "VGhpcyBp"
74  [2]=>
75  string(4) "IGk="
76  [3]=>
77  string(8) "NTY3ODk="
78  [4]=>
79  string(4) "ODk="
80}
81int(64)
82array(5) {
83  [0]=>
84  string(88) "zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868zrXOvc6/LiAwMTIzNDU2Nzg5Lg=="
85  [1]=>
86  string(16) "zrXOr869zrHOuSA="
87  [2]=>
88  string(4) "zr8="
89  [3]=>
90  string(8) "NTY3ODk="
91  [4]=>
92  string(4) "ODk="
93}
94Done
95