1--TEST-- 2Test mb_ereg() function : usage variations - pass different character classes as pattern for multibyte string 3--EXTENSIONS-- 4mbstring 5--SKIPIF-- 6<?php 7function_exists('mb_ereg') or die("skip mb_ereg() is not available in this build"); 8?> 9--FILE-- 10<?php 11/* 12 * Test how character classes match a multibyte string 13 */ 14 15echo "*** Testing mb_ereg() : usage variations ***\n"; 16 17mb_regex_encoding('utf-8'); 18 19//contains japanese characters, ASCII digits and different, UTF-8 encoded digits 20$string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII='); 21 22$character_classes = array ('[[:alnum:]]+', /*1*/ 23 '[[:alpha:]]+', 24 '[[:ascii:]]+', 25 '[[:blank:]]+', 26 '[[:cntrl:]]+',/*5*/ 27 '[[:digit:]]+', 28 '[[:graph:]]+', 29 '[[:lower:]]+', 30 '[[:print:]]+', 31 '[[:punct:]]+', /*10*/ 32 '[[:space:]]+', 33 '[[:upper:]]+', 34 '[[:xdigit:]]+'); /*13*/ 35 36$iterator = 1; 37foreach ($character_classes as $pattern) { 38 if (is_array(@$regs)) { 39 $regs = null; 40 } 41 echo "\n-- Iteration $iterator --\n"; 42 var_dump(mb_ereg($pattern, $string_mb, $regs)); 43 if ($regs) { 44 base64_encode_var_dump($regs); 45 } 46 $iterator++; 47} 48/** 49 * replicate a var dump of an array but outputted string values are base64 encoded 50 * 51 * @param array $regs 52 */ 53function base64_encode_var_dump($regs) { 54 if ($regs) { 55 echo "array(" . count($regs) . ") {\n"; 56 foreach ($regs as $key => $value) { 57 echo " [$key]=>\n "; 58 if (is_string($value)) { 59 var_dump(base64_encode($value)); 60 } else { 61 var_dump($value); 62 } 63 } 64 echo "}\n"; 65 } else { 66 echo "NULL\n"; 67 } 68} 69echo "Done"; 70 71?> 72--EXPECT-- 73*** Testing mb_ereg() : usage variations *** 74 75-- Iteration 1 -- 76bool(true) 77array(1) { 78 [0]=> 79 string(64) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZMDEyMzTvvJXvvJbvvJfvvJjvvJk=" 80} 81 82-- Iteration 2 -- 83bool(true) 84array(1) { 85 [0]=> 86 string(36) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ" 87} 88 89-- Iteration 3 -- 90bool(true) 91array(1) { 92 [0]=> 93 string(8) "MDEyMzQ=" 94} 95 96-- Iteration 4 -- 97bool(false) 98 99-- Iteration 5 -- 100bool(false) 101 102-- Iteration 6 -- 103bool(true) 104array(1) { 105 [0]=> 106 string(28) "MDEyMzTvvJXvvJbvvJfvvJjvvJk=" 107} 108 109-- Iteration 7 -- 110bool(true) 111array(1) { 112 [0]=> 113 string(68) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=" 114} 115 116-- Iteration 8 -- 117bool(false) 118 119-- Iteration 9 -- 120bool(true) 121array(1) { 122 [0]=> 123 string(68) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=" 124} 125 126-- Iteration 10 -- 127bool(true) 128array(1) { 129 [0]=> 130 string(4) "44CC" 131} 132 133-- Iteration 11 -- 134bool(false) 135 136-- Iteration 12 -- 137bool(false) 138 139-- Iteration 13 -- 140bool(true) 141array(1) { 142 [0]=> 143 string(8) "MDEyMzQ=" 144} 145Done 146