summaryrefslogtreecommitdiff
path: root/ext/mbstring/tests/mb_ereg_variation5.phpt
blob: c26d82ead5152e63563388e26909700401642e19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
--TEST--
Test mb_ereg() function : usage variations - Test anchors in regex
--SKIPIF--
<?php
extension_loaded('mbstring') or die('skip');
function_exists('mb_ereg') or die("skip mb_ereg() is not available in this build");
?>
--FILE--
<?php
/* Prototype  : int mb_ereg(string $pattern, string $string [, array $registers])
 * Description: Regular expression match for multibyte string
 * Source code: ext/mbstring/php_mbregex.c
 */

/*
 * Test mb_ereg with anchors (start and end of string) in $pattern
 */

echo "*** Testing mb_ereg() : usage variations ***\n";

mb_regex_encoding('utf-8');

$string_ascii = 'This is an English string. 0123456789.';
$string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');

$regex = '^.*?[[:blank:]]?[[:punct:][:digit:]]+\.?$';

echo "\nASCII String without \$regs arg:\t\t";
var_dump(mb_ereg($regex, $string_ascii));
echo "ASCII String with \$regs arg:\n";
var_dump(mb_ereg($regex, $string_ascii, $regs_ascii));
base64_encode_var_dump($regs_ascii);

echo "\nMultibyte String without \$regs arg:\t";
var_dump(mb_ereg($regex, $string_mb));
echo "Multubyte String with \$regs arg:\n";
var_dump(mb_ereg($regex, $string_mb, $regs_mb));
base64_encode_var_dump($regs_mb);

echo "Done";

/**
 * replicate a var dump of an array but outputted string values are base64 encoded
 *
 * @param array $regs
 */
function base64_encode_var_dump($regs) {
	if ($regs) {
		echo "array(" . count($regs) . ") {\n";
		foreach ($regs as $key => $value) {
			echo "  [$key]=>\n  ";
			if (is_string($value)) {
				var_dump(base64_encode($value));
			} else {
				var_dump($value);
			}
		}
		echo "}\n";
	} else {
		echo "NULL\n";
	}
}
?>
--EXPECTF--
*** Testing mb_ereg() : usage variations ***

ASCII String without $regs arg:		int(1)
ASCII String with $regs arg:
int(38)
array(1) {
  [0]=>
  string(52) "VGhpcyBpcyBhbiBFbmdsaXNoIHN0cmluZy4gMDEyMzQ1Njc4OS4="
}

Multibyte String without $regs arg:	int(1)
Multubyte String with $regs arg:
int(53)
array(1) {
  [0]=>
  string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII="
}
Done