![]() ![]() | ![]() |
1.1 misho 1: --TEST--
2: Test mb_split() function : usage variations - different parameter types for pattern
3: --SKIPIF--
4: <?php
5: extension_loaded('mbstring') or die('skip');
6: function_exists('mb_split') or die("skip mb_split() is not available in this build");
7: ?>
8: --FILE--
9: <?php
10: /* Prototype : proto array mb_split(string pattern, string string [, int limit])
11: * Description: split multibyte string into array by regular expression
12: * Source code: ext/mbstring/php_mbregex.c
13: * Alias to functions:
14: */
15:
16: echo "*** Testing mb_split() : usage variations ***\n";
17:
18: // Initialise function arguments not being substituted (if any)
19: $string = 'a b c d e f g';
20: $limit = 10;
21:
22: //get an unset variable
23: $unset_var = 10;
24: unset ($unset_var);
25:
26: // get a class
27: class classA
28: {
29: public function __toString() {
30: return "UTF-8";
31: }
32: }
33:
34: // heredoc string
35: $heredoc = <<<EOT
36: UTF-8
37: EOT;
38:
39: // get a resource variable
40: $fp = fopen(__FILE__, "r");
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: // resource variable
87: /*24*/ $fp
88: );
89:
90: // loop through each element of the array for pattern
91:
92: $iterator = 1;
93: foreach($inputs as $input) {
94: echo "\n-- Iteration $iterator --\n";
95: var_dump( mb_split($input, $string, $limit) );
96: $iterator++;
97: };
98: fclose($fp);
99: echo "Done";
100: ?>
101: --EXPECTF--
102: *** Testing mb_split() : usage variations ***
103:
104: -- Iteration 1 --
105: array(1) {
106: [0]=>
107: string(13) "a b c d e f g"
108: }
109:
110: -- Iteration 2 --
111: array(1) {
112: [0]=>
113: string(13) "a b c d e f g"
114: }
115:
116: -- Iteration 3 --
117: array(1) {
118: [0]=>
119: string(13) "a b c d e f g"
120: }
121:
122: -- Iteration 4 --
123: array(1) {
124: [0]=>
125: string(13) "a b c d e f g"
126: }
127:
128: -- Iteration 5 --
129: array(1) {
130: [0]=>
131: string(13) "a b c d e f g"
132: }
133:
134: -- Iteration 6 --
135: array(1) {
136: [0]=>
137: string(13) "a b c d e f g"
138: }
139:
140: -- Iteration 7 --
141: array(1) {
142: [0]=>
143: string(13) "a b c d e f g"
144: }
145:
146: -- Iteration 8 --
147: array(1) {
148: [0]=>
149: string(13) "a b c d e f g"
150: }
151:
152: -- Iteration 9 --
153: array(1) {
154: [0]=>
155: string(13) "a b c d e f g"
156: }
157:
158: -- Iteration 10 --
159: array(1) {
160: [0]=>
161: string(13) "a b c d e f g"
162: }
163:
164: -- Iteration 11 --
165: array(1) {
166: [0]=>
167: string(13) "a b c d e f g"
168: }
169:
170: -- Iteration 12 --
171: array(1) {
172: [0]=>
173: string(13) "a b c d e f g"
174: }
175:
176: -- Iteration 13 --
177: array(1) {
178: [0]=>
179: string(13) "a b c d e f g"
180: }
181:
182: -- Iteration 14 --
183: array(1) {
184: [0]=>
185: string(13) "a b c d e f g"
186: }
187:
188: -- Iteration 15 --
189: array(1) {
190: [0]=>
191: string(13) "a b c d e f g"
192: }
193:
194: -- Iteration 16 --
195: array(1) {
196: [0]=>
197: string(13) "a b c d e f g"
198: }
199:
200: -- Iteration 17 --
201: array(1) {
202: [0]=>
203: string(13) "a b c d e f g"
204: }
205:
206: -- Iteration 18 --
207: array(1) {
208: [0]=>
209: string(13) "a b c d e f g"
210: }
211:
212: -- Iteration 19 --
213: array(1) {
214: [0]=>
215: string(13) "a b c d e f g"
216: }
217:
218: -- Iteration 20 --
219: array(1) {
220: [0]=>
221: string(13) "a b c d e f g"
222: }
223:
224: -- Iteration 21 --
225: array(1) {
226: [0]=>
227: string(13) "a b c d e f g"
228: }
229:
230: -- Iteration 22 --
231: array(1) {
232: [0]=>
233: string(13) "a b c d e f g"
234: }
235:
236: -- Iteration 23 --
237: array(1) {
238: [0]=>
239: string(13) "a b c d e f g"
240: }
241:
242: -- Iteration 24 --
243:
244: Warning: mb_split() expects parameter 1 to be string, resource given in %s on line %d
245: bool(false)
1.1.1.2 ! misho 246: Done