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