Annotation of embedaddon/php/ext/mbstring/tests/mb_ereg_replace_variation3.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test mb_ereg_replace() function : usage variations
3: --SKIPIF--
4: <?php
5: extension_loaded('mbstring') or die('skip');
6: function_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:
16: echo "*** 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;
25: unset ($unset_var);
26:
27: // get a class
28: class classA
29: {
30: public function __toString() {
31: return "UTF-8";
32: }
33: }
34:
35: // heredoc string
36: $heredoc = <<<EOT
37: UTF-8
38: EOT;
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;
94: foreach($inputs as $input) {
95: echo "\n-- Iteration $iterator --\n";
96: var_dump( mb_ereg_replace($pattern, $replacement, $input, $option) );
97: $iterator++;
98: };
99:
100: fclose($fp);
101: echo "Done";
102: ?>
103: --EXPECTF--
104: *** Testing mb_ereg_replace() : usage variations ***
105:
106: -- Iteration 1 --
107: string(1) "0"
108:
109: -- Iteration 2 --
110: string(1) "1"
111:
112: -- Iteration 3 --
113: string(5) "12345"
114:
115: -- Iteration 4 --
116: string(5) "-2345"
117:
118: -- Iteration 5 --
119: string(4) "10.5"
120:
121: -- Iteration 6 --
122: string(5) "-10.5"
123:
124: -- Iteration 7 --
125: string(12) "123456789000"
126:
127: -- Iteration 8 --
128: string(13) "1.23456789E-9"
129:
130: -- Iteration 9 --
131: string(3) "0.5"
132:
133: -- Iteration 10 --
134: string(0) ""
135:
136: -- Iteration 11 --
137: string(0) ""
138:
139: -- Iteration 12 --
140: string(1) "1"
141:
142: -- Iteration 13 --
143: string(0) ""
144:
145: -- Iteration 14 --
146: string(1) "1"
147:
148: -- Iteration 15 --
149: string(0) ""
150:
151: -- Iteration 16 --
152: string(0) ""
153:
154: -- Iteration 17 --
155: string(0) ""
156:
157: -- Iteration 18 --
158: string(5) "UTF-8"
159:
160: -- Iteration 19 --
161: string(5) "UTF-8"
162:
163: -- Iteration 20 --
164: string(5) "UTF-8"
165:
166: -- Iteration 21 --
167: string(5) "UTF-8"
168:
169: -- Iteration 22 --
170: string(0) ""
171:
172: -- Iteration 23 --
173: string(0) ""
174:
175: -- Iteration 24 --
176:
177: Warning: mb_ereg_replace() expects parameter 3 to be string, resource given in %s on line %d
178: bool(false)
179: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>