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