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$string = '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, $input, $string, $option) );
97      $iterator++;
98};
99fclose($fp);
100echo "Done";
101?>
102--EXPECTF--
103*** Testing mb_ereg_replace() : usage variations ***
104
105-- Iteration 1 --
106string(10) "000000_000"
107
108-- Iteration 2 --
109string(10) "111111_111"
110
111-- Iteration 3 --
112string(46) "123451234512345123451234512345_123451234512345"
113
114-- Iteration 4 --
115string(46) "-2345-2345-2345-2345-2345-2345_-2345-2345-2345"
116
117-- Iteration 5 --
118string(37) "10.510.510.510.510.510.5_10.510.510.5"
119
120-- Iteration 6 --
121string(46) "-10.5-10.5-10.5-10.5-10.5-10.5_-10.5-10.5-10.5"
122
123-- Iteration 7 --
124string(109) "123456789000123456789000123456789000123456789000123456789000123456789000_123456789000123456789000123456789000"
125
126-- Iteration 8 --
127string(118) "1.23456789E-91.23456789E-91.23456789E-91.23456789E-91.23456789E-91.23456789E-9_1.23456789E-91.23456789E-91.23456789E-9"
128
129-- Iteration 9 --
130string(28) "0.50.50.50.50.50.5_0.50.50.5"
131
132-- Iteration 10 --
133string(1) "_"
134
135-- Iteration 11 --
136string(1) "_"
137
138-- Iteration 12 --
139string(10) "111111_111"
140
141-- Iteration 13 --
142string(1) "_"
143
144-- Iteration 14 --
145string(10) "111111_111"
146
147-- Iteration 15 --
148string(1) "_"
149
150-- Iteration 16 --
151string(1) "_"
152
153-- Iteration 17 --
154string(1) "_"
155
156-- Iteration 18 --
157string(46) "UTF-8UTF-8UTF-8UTF-8UTF-8UTF-8_UTF-8UTF-8UTF-8"
158
159-- Iteration 19 --
160string(46) "UTF-8UTF-8UTF-8UTF-8UTF-8UTF-8_UTF-8UTF-8UTF-8"
161
162-- Iteration 20 --
163string(46) "UTF-8UTF-8UTF-8UTF-8UTF-8UTF-8_UTF-8UTF-8UTF-8"
164
165-- Iteration 21 --
166string(46) "UTF-8UTF-8UTF-8UTF-8UTF-8UTF-8_UTF-8UTF-8UTF-8"
167
168-- Iteration 22 --
169string(1) "_"
170
171-- Iteration 23 --
172string(1) "_"
173
174-- Iteration 24 --
175
176Warning: mb_ereg_replace() expects parameter 2 to be string, resource given in %s on line %d
177bool(false)
178Done