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