1--TEST-- 2Test mb_ereg() function : usage variations - different regex features in $pattern 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 * Testing the following regular expression features match correctly: 13 * 1. definite quantifiers 14 * 2. Alternation 15 * 3. subpatterns in parentheses 16 */ 17 18echo "*** Testing mb_ereg() : usage variations ***\n"; 19 20if(mb_regex_encoding('utf-8') == true) { 21 echo "Regex encoding set to utf-8\n"; 22} else { 23 echo "Could not set regex encoding to utf-8\n"; 24} 25 26$string_ascii = 'This is an English string. 0123456789.'; 27$regex_ascii = '([A-Z]\w{1,4}is( [aeiou]|h)) ?.*\.\s[0-9]+(5([6-9][79]){2})[[:punct:]]$'; 28var_dump(mb_ereg($regex_ascii, $string_ascii, $regs_ascii)); 29base64_encode_var_dump($regs_ascii); 30 31$string_mb = base64_decode('zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868zrXOvc6/LiAwMTIzNDU2Nzg5Lg=='); 32$regex_mb = base64_decode("W86RLc6pXShcdysgKSvOtVvOsS3PiVxzXSvOui4qKM+MfM6/KS4qXC5cc1swLTldKyg1KFs2LTldWzc5XSl7Mn0pW1s6cHVuY3Q6XV0k"); 33var_dump(mb_ereg($regex_mb, $string_mb, $regs_mb)); 34base64_encode_var_dump($regs_mb); 35 36/** 37 * replicate a var dump of an array but outputted string values are base64 encoded 38 * 39 * @param array $regs 40 */ 41function base64_encode_var_dump($regs) { 42 if ($regs) { 43 echo "array(" . count($regs) . ") {\n"; 44 foreach ($regs as $key => $value) { 45 echo " [$key]=>\n "; 46 if (is_string($value)) { 47 var_dump(base64_encode($value)); 48 } else { 49 var_dump($value); 50 } 51 } 52 echo "}\n"; 53 } else { 54 echo "NULL\n"; 55 } 56} 57 58echo "Done"; 59 60?> 61--EXPECT-- 62*** Testing mb_ereg() : usage variations *** 63Regex encoding set to utf-8 64bool(true) 65array(5) { 66 [0]=> 67 string(52) "VGhpcyBpcyBhbiBFbmdsaXNoIHN0cmluZy4gMDEyMzQ1Njc4OS4=" 68 [1]=> 69 string(8) "VGhpcyBp" 70 [2]=> 71 string(4) "IGk=" 72 [3]=> 73 string(8) "NTY3ODk=" 74 [4]=> 75 string(4) "ODk=" 76} 77bool(true) 78array(5) { 79 [0]=> 80 string(88) "zpHPhc+Ez4wgzrXOr869zrHOuSDOtc67zrvOt869zrnOus+MIM66zrXOr868zrXOvc6/LiAwMTIzNDU2Nzg5Lg==" 81 [1]=> 82 string(16) "zrXOr869zrHOuSA=" 83 [2]=> 84 string(4) "zr8=" 85 [3]=> 86 string(8) "NTY3ODk=" 87 [4]=> 88 string(4) "ODk=" 89} 90Done 91