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 -- 112string(10) "string_val" 113 114-- Iteration 5 -- 115string(10) "string_val" 116 117-- Iteration 6 -- 118string(10) "string_val" 119 120-- Iteration 7 -- 121string(10) "string_val" 122 123-- Iteration 8 -- 124string(10) "string_val" 125 126-- Iteration 9 -- 127string(10) "string_val" 128 129-- Iteration 10 -- 130string(10) "string_val" 131 132-- Iteration 11 -- 133string(10) "string_val" 134 135-- Iteration 12 -- 136string(10) "string_val" 137 138-- Iteration 13 -- 139string(10) "string_val" 140 141-- Iteration 14 -- 142string(10) "string_val" 143 144-- Iteration 15 -- 145string(10) "string_val" 146 147-- Iteration 16 -- 148string(120) "string_valsstring_valtstring_valrstring_valistring_valnstring_valgstring_val_string_valvstring_valastring_vallstring_val" 149 150-- Iteration 17 -- 151string(120) "string_valsstring_valtstring_valrstring_valistring_valnstring_valgstring_val_string_valvstring_valastring_vallstring_val" 152 153-- Iteration 18 -- 154string(10) "string_val" 155 156-- Iteration 19 -- 157string(10) "string_val" 158 159-- Iteration 20 -- 160string(10) "string_val" 161 162-- Iteration 21 -- 163string(10) "string_val" 164 165-- Iteration 22 -- 166string(10) "string_val" 167 168-- Iteration 23 -- 169string(10) "string_val" 170Done 171