1--TEST--
2Test mb_substr() function : usage variations - test different encodings
3--SKIPIF--
4<?php
5extension_loaded('mbstring') or die('skip');
6function_exists('mb_substr') or die("skip mb_substr() is not available in this build");
7?>
8--FILE--
9<?php
10/* Prototype  : string mb_substr(string $str, int $start [, int $length [, string $encoding]])
11 * Description: Returns part of a string
12 * Source code: ext/mbstring/mbstring.c
13 */
14
15/*
16 * Pass all encodings listed on php.net to test that function recognises them.
17 * NB: The strings passed are *NOT* necessarily encoded in the encoding passed to the function.
18 * This test is purely to see whether the function recognises the encoding.
19 */
20
21echo "*** Testing mb_substr() : usage variations ***\n";
22
23$encoding = array('UCS-4',			/*1*/
24                  'UCS-4BE',
25                  'UCS-4LE',
26                  'UCS-2',
27                  'UCS-2BE',		/*5*/
28                  'UCS-2LE',
29                  'UTF-32',
30                  'UTF-32BE',
31                  'UTF-32LE',
32                  'UTF-16',			/*10*/
33                  'UTF-16BE',
34                  'UTF-16LE',
35                  'UTF-7',
36                  'UTF7-IMAP',
37                  'UTF-8',			/*15*/
38                  'ASCII',
39                  'EUC-JP',
40                  'SJIS',
41                  'eucJP-win',
42                  'SJIS-win',		/*20*/
43                  'ISO-2022-JP',
44                  'JIS',
45                  'ISO-8859-1',
46                  'ISO-8859-2',
47                  'ISO-8859-3',		/*25*/
48                  'ISO-8859-4',
49                  'ISO-8859-5',
50                  'ISO-8859-6',
51                  'ISO-8859-7',
52                  'ISO-8859-8',		/*30*/
53                  'ISO-8859-9',
54                  'ISO-8859-10',
55                  'ISO-8859-13',
56                  'ISO-8859-14',
57                  'ISO-8859-15',	/*35*/
58                  'byte2be',
59                  'byte2le',
60                  'byte4be',
61                  'byte4le',
62                  'BASE64',			/*40*/
63                  'HTML-ENTITIES',
64                  '7bit',
65                  '8bit',
66                  'EUC-CN',
67                  'CP936',			/*45*/
68                  'HZ',
69                  'EUC-TW',
70                  'CP950',
71                  'BIG-5',
72                  'EUC-KR',			/*50*/
73                  'UHC',
74                  'ISO-2022-KR',
75                  'Windows-1251',
76                  'Windows-1252',
77                  'CP866',			/*55*/
78                  'KOI8-R');		/*56*/
79
80
81
82$iterator = 1;
83$string_ascii = 'abc def';
84//Japanese string encoded in UTF-8
85$string_mb = base64_decode('44K/44OT44Ol44Os44O844OG44Kj44Oz44Kw44O744Oe44K344O844Oz44O744Kr44Oz44OR44OL44O8');
86
87foreach($encoding as $enc) {
88	echo "\n-- Iteration $iterator: $enc --\n";
89
90	echo "-- ASCII String --\n";
91	if (mb_substr($string_ascii, 1, 5, $enc)) {
92		echo "Encoding $enc recognised\n";
93	} else {
94		echo "Encoding $enc not recognised\n";
95	}
96
97	echo "-- Multibyte String --\n";
98	if (mb_substr($string_mb, 1, 5, $enc)) {
99		echo "Encoding $enc recognised\n";
100	} else {
101		echo "Encoding $enc not recognised\n";
102	}
103}
104
105echo "Done";
106?>
107--EXPECT--
108*** Testing mb_substr() : usage variations ***
109
110-- Iteration 1: UCS-4 --
111-- ASCII String --
112Encoding UCS-4 recognised
113-- Multibyte String --
114Encoding UCS-4 recognised
115
116-- Iteration 1: UCS-4BE --
117-- ASCII String --
118Encoding UCS-4BE recognised
119-- Multibyte String --
120Encoding UCS-4BE recognised
121
122-- Iteration 1: UCS-4LE --
123-- ASCII String --
124Encoding UCS-4LE recognised
125-- Multibyte String --
126Encoding UCS-4LE recognised
127
128-- Iteration 1: UCS-2 --
129-- ASCII String --
130Encoding UCS-2 recognised
131-- Multibyte String --
132Encoding UCS-2 recognised
133
134-- Iteration 1: UCS-2BE --
135-- ASCII String --
136Encoding UCS-2BE recognised
137-- Multibyte String --
138Encoding UCS-2BE recognised
139
140-- Iteration 1: UCS-2LE --
141-- ASCII String --
142Encoding UCS-2LE recognised
143-- Multibyte String --
144Encoding UCS-2LE recognised
145
146-- Iteration 1: UTF-32 --
147-- ASCII String --
148Encoding UTF-32 recognised
149-- Multibyte String --
150Encoding UTF-32 recognised
151
152-- Iteration 1: UTF-32BE --
153-- ASCII String --
154Encoding UTF-32BE recognised
155-- Multibyte String --
156Encoding UTF-32BE recognised
157
158-- Iteration 1: UTF-32LE --
159-- ASCII String --
160Encoding UTF-32LE recognised
161-- Multibyte String --
162Encoding UTF-32LE recognised
163
164-- Iteration 1: UTF-16 --
165-- ASCII String --
166Encoding UTF-16 recognised
167-- Multibyte String --
168Encoding UTF-16 recognised
169
170-- Iteration 1: UTF-16BE --
171-- ASCII String --
172Encoding UTF-16BE recognised
173-- Multibyte String --
174Encoding UTF-16BE recognised
175
176-- Iteration 1: UTF-16LE --
177-- ASCII String --
178Encoding UTF-16LE recognised
179-- Multibyte String --
180Encoding UTF-16LE recognised
181
182-- Iteration 1: UTF-7 --
183-- ASCII String --
184Encoding UTF-7 recognised
185-- Multibyte String --
186Encoding UTF-7 recognised
187
188-- Iteration 1: UTF7-IMAP --
189-- ASCII String --
190Encoding UTF7-IMAP recognised
191-- Multibyte String --
192Encoding UTF7-IMAP recognised
193
194-- Iteration 1: UTF-8 --
195-- ASCII String --
196Encoding UTF-8 recognised
197-- Multibyte String --
198Encoding UTF-8 recognised
199
200-- Iteration 1: ASCII --
201-- ASCII String --
202Encoding ASCII recognised
203-- Multibyte String --
204Encoding ASCII recognised
205
206-- Iteration 1: EUC-JP --
207-- ASCII String --
208Encoding EUC-JP recognised
209-- Multibyte String --
210Encoding EUC-JP recognised
211
212-- Iteration 1: SJIS --
213-- ASCII String --
214Encoding SJIS recognised
215-- Multibyte String --
216Encoding SJIS recognised
217
218-- Iteration 1: eucJP-win --
219-- ASCII String --
220Encoding eucJP-win recognised
221-- Multibyte String --
222Encoding eucJP-win recognised
223
224-- Iteration 1: SJIS-win --
225-- ASCII String --
226Encoding SJIS-win recognised
227-- Multibyte String --
228Encoding SJIS-win recognised
229
230-- Iteration 1: ISO-2022-JP --
231-- ASCII String --
232Encoding ISO-2022-JP recognised
233-- Multibyte String --
234Encoding ISO-2022-JP recognised
235
236-- Iteration 1: JIS --
237-- ASCII String --
238Encoding JIS recognised
239-- Multibyte String --
240Encoding JIS recognised
241
242-- Iteration 1: ISO-8859-1 --
243-- ASCII String --
244Encoding ISO-8859-1 recognised
245-- Multibyte String --
246Encoding ISO-8859-1 recognised
247
248-- Iteration 1: ISO-8859-2 --
249-- ASCII String --
250Encoding ISO-8859-2 recognised
251-- Multibyte String --
252Encoding ISO-8859-2 recognised
253
254-- Iteration 1: ISO-8859-3 --
255-- ASCII String --
256Encoding ISO-8859-3 recognised
257-- Multibyte String --
258Encoding ISO-8859-3 recognised
259
260-- Iteration 1: ISO-8859-4 --
261-- ASCII String --
262Encoding ISO-8859-4 recognised
263-- Multibyte String --
264Encoding ISO-8859-4 recognised
265
266-- Iteration 1: ISO-8859-5 --
267-- ASCII String --
268Encoding ISO-8859-5 recognised
269-- Multibyte String --
270Encoding ISO-8859-5 recognised
271
272-- Iteration 1: ISO-8859-6 --
273-- ASCII String --
274Encoding ISO-8859-6 recognised
275-- Multibyte String --
276Encoding ISO-8859-6 recognised
277
278-- Iteration 1: ISO-8859-7 --
279-- ASCII String --
280Encoding ISO-8859-7 recognised
281-- Multibyte String --
282Encoding ISO-8859-7 recognised
283
284-- Iteration 1: ISO-8859-8 --
285-- ASCII String --
286Encoding ISO-8859-8 recognised
287-- Multibyte String --
288Encoding ISO-8859-8 recognised
289
290-- Iteration 1: ISO-8859-9 --
291-- ASCII String --
292Encoding ISO-8859-9 recognised
293-- Multibyte String --
294Encoding ISO-8859-9 recognised
295
296-- Iteration 1: ISO-8859-10 --
297-- ASCII String --
298Encoding ISO-8859-10 recognised
299-- Multibyte String --
300Encoding ISO-8859-10 recognised
301
302-- Iteration 1: ISO-8859-13 --
303-- ASCII String --
304Encoding ISO-8859-13 recognised
305-- Multibyte String --
306Encoding ISO-8859-13 recognised
307
308-- Iteration 1: ISO-8859-14 --
309-- ASCII String --
310Encoding ISO-8859-14 recognised
311-- Multibyte String --
312Encoding ISO-8859-14 recognised
313
314-- Iteration 1: ISO-8859-15 --
315-- ASCII String --
316Encoding ISO-8859-15 recognised
317-- Multibyte String --
318Encoding ISO-8859-15 recognised
319
320-- Iteration 1: byte2be --
321-- ASCII String --
322Encoding byte2be recognised
323-- Multibyte String --
324Encoding byte2be recognised
325
326-- Iteration 1: byte2le --
327-- ASCII String --
328Encoding byte2le recognised
329-- Multibyte String --
330Encoding byte2le recognised
331
332-- Iteration 1: byte4be --
333-- ASCII String --
334Encoding byte4be recognised
335-- Multibyte String --
336Encoding byte4be recognised
337
338-- Iteration 1: byte4le --
339-- ASCII String --
340Encoding byte4le recognised
341-- Multibyte String --
342Encoding byte4le recognised
343
344-- Iteration 1: BASE64 --
345-- ASCII String --
346Encoding BASE64 recognised
347-- Multibyte String --
348Encoding BASE64 recognised
349
350-- Iteration 1: HTML-ENTITIES --
351-- ASCII String --
352Encoding HTML-ENTITIES recognised
353-- Multibyte String --
354Encoding HTML-ENTITIES recognised
355
356-- Iteration 1: 7bit --
357-- ASCII String --
358Encoding 7bit recognised
359-- Multibyte String --
360Encoding 7bit recognised
361
362-- Iteration 1: 8bit --
363-- ASCII String --
364Encoding 8bit recognised
365-- Multibyte String --
366Encoding 8bit recognised
367
368-- Iteration 1: EUC-CN --
369-- ASCII String --
370Encoding EUC-CN recognised
371-- Multibyte String --
372Encoding EUC-CN recognised
373
374-- Iteration 1: CP936 --
375-- ASCII String --
376Encoding CP936 recognised
377-- Multibyte String --
378Encoding CP936 recognised
379
380-- Iteration 1: HZ --
381-- ASCII String --
382Encoding HZ recognised
383-- Multibyte String --
384Encoding HZ recognised
385
386-- Iteration 1: EUC-TW --
387-- ASCII String --
388Encoding EUC-TW recognised
389-- Multibyte String --
390Encoding EUC-TW recognised
391
392-- Iteration 1: CP950 --
393-- ASCII String --
394Encoding CP950 recognised
395-- Multibyte String --
396Encoding CP950 recognised
397
398-- Iteration 1: BIG-5 --
399-- ASCII String --
400Encoding BIG-5 recognised
401-- Multibyte String --
402Encoding BIG-5 recognised
403
404-- Iteration 1: EUC-KR --
405-- ASCII String --
406Encoding EUC-KR recognised
407-- Multibyte String --
408Encoding EUC-KR recognised
409
410-- Iteration 1: UHC --
411-- ASCII String --
412Encoding UHC recognised
413-- Multibyte String --
414Encoding UHC recognised
415
416-- Iteration 1: ISO-2022-KR --
417-- ASCII String --
418Encoding ISO-2022-KR recognised
419-- Multibyte String --
420Encoding ISO-2022-KR recognised
421
422-- Iteration 1: Windows-1251 --
423-- ASCII String --
424Encoding Windows-1251 recognised
425-- Multibyte String --
426Encoding Windows-1251 recognised
427
428-- Iteration 1: Windows-1252 --
429-- ASCII String --
430Encoding Windows-1252 recognised
431-- Multibyte String --
432Encoding Windows-1252 recognised
433
434-- Iteration 1: CP866 --
435-- ASCII String --
436Encoding CP866 recognised
437-- Multibyte String --
438Encoding CP866 recognised
439
440-- Iteration 1: KOI8-R --
441-- ASCII String --
442Encoding KOI8-R recognised
443-- Multibyte String --
444Encoding KOI8-R recognised
445Done
446