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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
--TEST--
Test mb_ereg() function : usage variations - pass different character classes to see they match correctly
--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 that mb_ereg can match correctly when passed different character classes.
*/
echo "*** Testing mb_ereg() : variation ***\n";
mb_regex_encoding('utf-8'); // have to set otherwise won't match $mb properly
$mb = base64_decode('5pel5pys6Kqe');
$character_classes = array (b'aB1' => b'[[:alnum:]]+', /*1*/
b'aBcD' => b'[[:alpha:]]+',
b'ab/=' => b'[[:ascii:]]+',
b" \t" => b'[[:blank:]]+',
b'234' => b'[[:digit:]]+', /*5*/
"$mb" => b'[[:graph:]]+',
b'fjds' => b'[[:lower:]]+',
b"$mb\t" => b'[[:print:]]+',
b'.!"*@' => b'[[:punct:]]+',
b"\t" => b'[[:space:]]+', /*10*/
b'IDSJV' => b'[[:upper:]]+',
b'3b5D' => b'[[:xdigit:]]+'); /*12*/
$iterator = 1;
foreach($character_classes as $string => $pattern) {
if (is_array(@$regs)) {
$regs = null;
}
// make sure any multibyte output is in base 64
echo "\n-- Iteration $iterator --\n";
var_dump(mb_ereg($pattern, $string, $regs));
base64_encode_var_dump($regs);
$iterator++;
}
/**
* 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";
}
}
echo "Done";
?>
--EXPECT--
*** Testing mb_ereg() : variation ***
-- Iteration 1 --
int(3)
array(1) {
[0]=>
string(4) "YUIx"
}
-- Iteration 2 --
int(4)
array(1) {
[0]=>
string(8) "YUJjRA=="
}
-- Iteration 3 --
int(4)
array(1) {
[0]=>
string(8) "YWIvPQ=="
}
-- Iteration 4 --
int(2)
array(1) {
[0]=>
string(4) "IAk="
}
-- Iteration 5 --
int(3)
array(1) {
[0]=>
string(4) "MjM0"
}
-- Iteration 6 --
int(9)
array(1) {
[0]=>
string(12) "5pel5pys6Kqe"
}
-- Iteration 7 --
int(4)
array(1) {
[0]=>
string(8) "Zmpkcw=="
}
-- Iteration 8 --
int(10)
array(1) {
[0]=>
string(16) "5pel5pys6KqeCQ=="
}
-- Iteration 9 --
int(5)
array(1) {
[0]=>
string(8) "LiEiKkA="
}
-- Iteration 10 --
int(1)
array(1) {
[0]=>
string(4) "CQ=="
}
-- Iteration 11 --
int(5)
array(1) {
[0]=>
string(8) "SURTSlY="
}
-- Iteration 12 --
int(4)
array(1) {
[0]=>
string(8) "M2I1RA=="
}
Done
|