1--TEST-- 2Test mb_ereg() function : basic functionality 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 basic functionality of mb_ereg 13 */ 14 15echo "*** Testing mb_ereg() : basic functionality ***\n"; 16 17if(mb_regex_encoding('utf-8') == true) { 18 echo "Regex encoding set to utf-8\n"; 19} else { 20 echo "Could not set regex encoding to utf-8\n"; 21} 22$string_ascii = 'This is an English string. 0123456789.'; 23$regex_ascii1 = '(.*is)+.*\.[[:blank:]][0-9]{9}'; 24$regex_ascii2 = '.*is+'; 25 26$string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII='); 27$regex_mb1 = base64_decode('KOaXpeacrOiqnikuKj8oWzEtOV0rKQ=='); 28$regex_mb2 = base64_decode('5LiW55WM'); 29 30echo "\n**-- ASCII String --**\n"; 31echo "-- Without \$regs argument--\n"; 32var_dump(mb_ereg($regex_ascii1, $string_ascii)); 33var_dump(mb_ereg($regex_ascii2, $string_ascii)); 34echo "--With \$regs argument --\n"; 35var_dump(mb_ereg($regex_ascii1, $string_ascii, $regs_ascii1)); 36base64_encode_var_dump($regs_ascii1); 37var_dump(mb_ereg($regex_ascii2, $string_ascii, $regs_ascii2)); 38base64_encode_var_dump($regs_ascii2); 39 40echo "\n**-- Multibyte String --**\n"; 41echo "-- Without \$regs argument --\n"; 42var_dump(mb_ereg($regex_mb1, $string_mb)); 43var_dump(mb_ereg($regex_mb2, $string_mb)); 44echo "-- With \$regs argument --\n"; 45var_dump(mb_ereg($regex_mb1, $string_mb, $regs_mb1)); 46base64_encode_var_dump($regs_mb1); 47var_dump(mb_ereg($regex_mb2, $string_mb, $regs_mb2)); 48var_dump($regs_mb2); 49 50echo "Done"; 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} 73?> 74--EXPECT-- 75*** Testing mb_ereg() : basic functionality *** 76Regex encoding set to utf-8 77 78**-- ASCII String --** 79-- Without $regs argument-- 80bool(true) 81bool(true) 82--With $regs argument -- 83bool(true) 84array(2) { 85 [0]=> 86 string(48) "VGhpcyBpcyBhbiBFbmdsaXNoIHN0cmluZy4gMDEyMzQ1Njc4" 87 [1]=> 88 string(24) "VGhpcyBpcyBhbiBFbmdsaXM=" 89} 90bool(true) 91array(1) { 92 [0]=> 93 string(24) "VGhpcyBpcyBhbiBFbmdsaXM=" 94} 95 96**-- Multibyte String --** 97-- Without $regs argument -- 98bool(true) 99bool(false) 100-- With $regs argument -- 101bool(true) 102array(3) { 103 [0]=> 104 string(48) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzQ=" 105 [1]=> 106 string(12) "5pel5pys6Kqe" 107 [2]=> 108 string(8) "MTIzNA==" 109} 110bool(false) 111array(0) { 112} 113Done 114