1--TEST-- 2Test mb_ereg() function : basic functionality 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 basic functionality of mb_ereg 17 */ 18 19echo "*** Testing mb_ereg() : basic functionality ***\n"; 20 21if(mb_regex_encoding('utf-8') == true) { 22 echo "Regex encoding set to utf-8\n"; 23} else { 24 echo "Could not set regex encoding to utf-8\n"; 25} 26$string_ascii = 'This is an English string. 0123456789.'; 27$regex_ascii1 = '(.*is)+.*\.[[:blank:]][0-9]{9}'; 28$regex_ascii2 = '.*is+'; 29 30$string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII='); 31$regex_mb1 = base64_decode('KOaXpeacrOiqnikuKj8oWzEtOV0rKQ=='); 32$regex_mb2 = base64_decode('5LiW55WM'); 33 34echo "\n**-- ASCII String --**\n"; 35echo "-- Without \$regs argument--\n"; 36var_dump(mb_ereg($regex_ascii1, $string_ascii)); 37var_dump(mb_ereg($regex_ascii2, $string_ascii)); 38echo "--With \$regs argument --\n"; 39var_dump(mb_ereg($regex_ascii1, $string_ascii, $regs_ascii1)); 40base64_encode_var_dump($regs_ascii1); 41var_dump(mb_ereg($regex_ascii2, $string_ascii, $regs_ascii2)); 42base64_encode_var_dump($regs_ascii2); 43 44echo "\n**-- Multibyte String --**\n"; 45echo "-- Without \$regs argument --\n"; 46var_dump(mb_ereg($regex_mb1, $string_mb)); 47var_dump(mb_ereg($regex_mb2, $string_mb)); 48echo "-- With \$regs argument --\n"; 49var_dump(mb_ereg($regex_mb1, $string_mb, $regs_mb1)); 50base64_encode_var_dump($regs_mb1); 51var_dump(mb_ereg($regex_mb2, $string_mb, $regs_mb2)); 52var_dump($regs_mb2); 53 54echo "Done"; 55 56/** 57 * replicate a var dump of an array but outputted string values are base64 encoded 58 * 59 * @param array $regs 60 */ 61function base64_encode_var_dump($regs) { 62 if ($regs) { 63 echo "array(" . count($regs) . ") {\n"; 64 foreach ($regs as $key => $value) { 65 echo " [$key]=>\n "; 66 if (is_string($value)) { 67 var_dump(base64_encode($value)); 68 } else { 69 var_dump($value); 70 } 71 } 72 echo "}\n"; 73 } else { 74 echo "NULL\n"; 75 } 76} 77?> 78--EXPECT-- 79*** Testing mb_ereg() : basic functionality *** 80Regex encoding set to utf-8 81 82**-- ASCII String --** 83-- Without $regs argument-- 84int(1) 85int(1) 86--With $regs argument -- 87int(36) 88array(2) { 89 [0]=> 90 string(48) "VGhpcyBpcyBhbiBFbmdsaXNoIHN0cmluZy4gMDEyMzQ1Njc4" 91 [1]=> 92 string(24) "VGhpcyBpcyBhbiBFbmdsaXM=" 93} 94int(17) 95array(1) { 96 [0]=> 97 string(24) "VGhpcyBpcyBhbiBFbmdsaXM=" 98} 99 100**-- Multibyte String --** 101-- Without $regs argument -- 102int(1) 103bool(false) 104-- With $regs argument -- 105int(35) 106array(3) { 107 [0]=> 108 string(48) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzQ=" 109 [1]=> 110 string(12) "5pel5pys6Kqe" 111 [2]=> 112 string(8) "MTIzNA==" 113} 114bool(false) 115array(0) { 116} 117Done 118