1--TEST-- 2Test mb_ereg() function : usage variations - pass different character classes to see they match correctly 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"); 7version_compare(MB_ONIGURUMA_VERSION, '6.1.0', '>=') or die("skip requires oniguruma >= 6.1.0"); 8?> 9--FILE-- 10<?php 11/* 12 * test that mb_ereg can match correctly when passed different character classes. 13 */ 14 15echo "*** Testing mb_ereg() : variation ***\n"; 16 17 18mb_regex_encoding('utf-8'); // have to set otherwise won't match $mb properly 19$mb = base64_decode('5pel5pys6Kqe'); 20$character_classes = array ('aB1' => '[[:alnum:]]+', /*1*/ 21 'aBcD' => '[[:alpha:]]+', 22 'ab/=' => '[[:ascii:]]+', 23 " \t" => '[[:blank:]]+', 24 '234' => '[[:digit:]]+', /*5*/ 25 "$mb" => '[[:graph:]]+', 26 'fjds' => '[[:lower:]]+', 27 "$mb\t" => '[[:print:]]+', 28 '.!"*@' => '[[:punct:]]+', 29 "\t" => '[[:space:]]+', /*10*/ 30 'IDSJV' => '[[:upper:]]+', 31 '3b5D' => '[[:xdigit:]]+'); /*12*/ 32 33$iterator = 1; 34foreach($character_classes as $string => $pattern) { 35 if (is_array(@$regs)) { 36 $regs = null; 37 } 38 // make sure any multibyte output is in base 64 39 echo "\n-- Iteration $iterator --\n"; 40 var_dump(mb_ereg($pattern, $string, $regs)); 41 base64_encode_var_dump($regs); 42 $iterator++; 43} 44/** 45 * replicate a var dump of an array but outputted string values are base64 encoded 46 * 47 * @param array $regs 48 */ 49function base64_encode_var_dump($regs) { 50 if ($regs) { 51 echo "array(" . count($regs) . ") {\n"; 52 foreach ($regs as $key => $value) { 53 echo " [$key]=>\n "; 54 if (is_string($value)) { 55 var_dump(base64_encode($value)); 56 } else { 57 var_dump($value); 58 } 59 } 60 echo "}\n"; 61 } else { 62 echo "NULL\n"; 63 } 64} 65 66echo "Done"; 67?> 68--EXPECT-- 69*** Testing mb_ereg() : variation *** 70 71-- Iteration 1 -- 72bool(true) 73array(1) { 74 [0]=> 75 string(4) "YUIx" 76} 77 78-- Iteration 2 -- 79bool(true) 80array(1) { 81 [0]=> 82 string(8) "YUJjRA==" 83} 84 85-- Iteration 3 -- 86bool(true) 87array(1) { 88 [0]=> 89 string(8) "YWIvPQ==" 90} 91 92-- Iteration 4 -- 93bool(true) 94array(1) { 95 [0]=> 96 string(4) "IAk=" 97} 98 99-- Iteration 5 -- 100bool(true) 101array(1) { 102 [0]=> 103 string(4) "MjM0" 104} 105 106-- Iteration 6 -- 107bool(true) 108array(1) { 109 [0]=> 110 string(12) "5pel5pys6Kqe" 111} 112 113-- Iteration 7 -- 114bool(true) 115array(1) { 116 [0]=> 117 string(8) "Zmpkcw==" 118} 119 120-- Iteration 8 -- 121bool(true) 122array(1) { 123 [0]=> 124 string(12) "5pel5pys6Kqe" 125} 126 127-- Iteration 9 -- 128bool(true) 129array(1) { 130 [0]=> 131 string(8) "LiEiKkA=" 132} 133 134-- Iteration 10 -- 135bool(true) 136array(1) { 137 [0]=> 138 string(4) "CQ==" 139} 140 141-- Iteration 11 -- 142bool(true) 143array(1) { 144 [0]=> 145 string(8) "SURTSlY=" 146} 147 148-- Iteration 12 -- 149bool(true) 150array(1) { 151 [0]=> 152 string(8) "M2I1RA==" 153} 154Done 155