1--TEST-- 2Test mb_ereg_replace() function : usage variations - <type here specifics of this variation> 3--INI-- 4error_reporting=E_ALL & ~E_NOTICE 5--SKIPIF-- 6<?php 7extension_loaded('mbstring') or die('skip'); 8function_exists('mb_ereg_replace') or die("skip mb_ereg_replace() is not available in this build"); 9?> 10--FILE-- 11<?php 12/* Prototype : proto string mb_ereg_replace(string pattern, string replacement, string string [, string option]) 13 * Description: Replace regular expression for multibyte string 14 * Source code: ext/mbstring/php_mbregex.c 15 * Alias to functions: 16 */ 17 18echo "*** Testing mb_ereg_replace() : usage variations ***\n"; 19 20// Initialise function arguments not being substituted (if any) 21$replacement = 'string_val'; 22$string = 'string_val'; 23$option = ''; 24 25//get an unset variable 26$unset_var = 10; 27unset ($unset_var); 28 29// get a class 30class classA 31{ 32 public function __toString() { 33 return "UTF-8"; 34 } 35} 36 37// heredoc string 38$heredoc = <<<EOT 39UTF-8 40EOT; 41 42// unexpected values to be passed to $encoding argument 43$inputs = array( 44 45 // int data 46/*1*/ 0, 47 1, 48 12345, 49 -2345, 50 51 // float data 52/*5*/ 10.5, 53 -10.5, 54 12.3456789000e10, 55 12.3456789000E-10, 56 .5, 57 58 // null data 59/*10*/ NULL, 60 null, 61 62 // boolean data 63/*12*/ true, 64 false, 65 TRUE, 66 FALSE, 67 68 // empty data 69/*16*/ "", 70 '', 71 72 // string data 73/*18*/ "UTF-8", 74 'UTF-8', 75 $heredoc, 76 77 // object data 78/*21*/ new classA(), 79 80 // undefined data 81/*22*/ @$undefined_var, 82 83 // unset data 84/*23*/ @$unset_var, 85 86); 87 88// loop through each element of the array for pattern 89 90$iterator = 1; 91foreach($inputs as $input) { 92 echo "\n-- Iteration $iterator --\n"; 93 var_dump( mb_ereg_replace($input, $replacement, $string, $option) ); 94 $iterator++; 95}; 96 97echo "Done"; 98?> 99--EXPECTF-- 100*** Testing mb_ereg_replace() : usage variations *** 101 102-- Iteration 1 -- 103string(10) "string_val" 104 105-- Iteration 2 -- 106string(10) "string_val" 107 108-- Iteration 3 -- 109string(10) "string_val" 110 111-- Iteration 4 -- 112 113Warning: mb_ereg_replace(): Pattern is not valid under UTF-8 encoding in %s on line %d 114bool(false) 115 116-- Iteration 5 -- 117string(10) "string_val" 118 119-- Iteration 6 -- 120 121Warning: mb_ereg_replace(): Pattern is not valid under UTF-8 encoding in %s on line %d 122bool(false) 123 124-- Iteration 7 -- 125string(10) "string_val" 126 127-- Iteration 8 -- 128string(10) "string_val" 129 130-- Iteration 9 -- 131string(10) "string_val" 132 133-- Iteration 10 -- 134string(10) "string_val" 135 136-- Iteration 11 -- 137string(10) "string_val" 138 139-- Iteration 12 -- 140string(10) "string_val" 141 142-- Iteration 13 -- 143string(10) "string_val" 144 145-- Iteration 14 -- 146string(10) "string_val" 147 148-- Iteration 15 -- 149string(10) "string_val" 150 151-- Iteration 16 -- 152string(120) "string_valsstring_valtstring_valrstring_valistring_valnstring_valgstring_val_string_valvstring_valastring_vallstring_val" 153 154-- Iteration 17 -- 155string(120) "string_valsstring_valtstring_valrstring_valistring_valnstring_valgstring_val_string_valvstring_valastring_vallstring_val" 156 157-- Iteration 18 -- 158string(10) "string_val" 159 160-- Iteration 19 -- 161string(10) "string_val" 162 163-- Iteration 20 -- 164string(10) "string_val" 165 166-- Iteration 21 -- 167string(10) "string_val" 168 169-- Iteration 22 -- 170string(10) "string_val" 171 172-- Iteration 23 -- 173string(10) "string_val" 174Done 175