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