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