1--TEST-- 2Test mb_ereg() function : usage variations - Test anchors in regex 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 mb_ereg with anchors (start and end of string) in $pattern 17 */ 18 19echo "*** Testing mb_ereg() : usage variations ***\n"; 20 21mb_regex_encoding('utf-8'); 22 23$string_ascii = 'This is an English string. 0123456789.'; 24$string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII='); 25 26$regex = '^.*?[[:blank:]]?[[:punct:][:digit:]]+\.?$'; 27 28echo "\nASCII String without \$regs arg:\t\t"; 29var_dump(mb_ereg($regex, $string_ascii)); 30echo "ASCII String with \$regs arg:\n"; 31var_dump(mb_ereg($regex, $string_ascii, $regs_ascii)); 32base64_encode_var_dump($regs_ascii); 33 34echo "\nMultibyte String without \$regs arg:\t"; 35var_dump(mb_ereg($regex, $string_mb)); 36echo "Multubyte String with \$regs arg:\n"; 37var_dump(mb_ereg($regex, $string_mb, $regs_mb)); 38base64_encode_var_dump($regs_mb); 39 40echo "Done"; 41 42/** 43 * replicate a var dump of an array but outputted string values are base64 encoded 44 * 45 * @param array $regs 46 */ 47function base64_encode_var_dump($regs) { 48 if ($regs) { 49 echo "array(" . count($regs) . ") {\n"; 50 foreach ($regs as $key => $value) { 51 echo " [$key]=>\n "; 52 if (is_string($value)) { 53 var_dump(base64_encode($value)); 54 } else { 55 var_dump($value); 56 } 57 } 58 echo "}\n"; 59 } else { 60 echo "NULL\n"; 61 } 62} 63?> 64--EXPECTF-- 65*** Testing mb_ereg() : usage variations *** 66 67ASCII String without $regs arg: int(1) 68ASCII String with $regs arg: 69int(38) 70array(1) { 71 [0]=> 72 string(52) "VGhpcyBpcyBhbiBFbmdsaXNoIHN0cmluZy4gMDEyMzQ1Njc4OS4=" 73} 74 75Multibyte String without $regs arg: int(1) 76Multubyte String with $regs arg: 77int(53) 78array(1) { 79 [0]=> 80 string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=" 81} 82Done 83