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