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/* 11 * Test all listed encoding types from php.net to check all are known to function 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_regex_encoding() : 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$iterator = 1; 76foreach($encoding as $enc) { 77 echo "\n-- Iteration $iterator --\n"; 78 var_dump(mb_regex_encoding()); 79 try { 80 var_dump(mb_regex_encoding($enc)); 81 } catch (\ValueError $e) { 82 echo $e->getMessage() . \PHP_EOL; 83 } 84 var_dump(mb_regex_encoding()); 85 $iterator++; 86} 87echo "Done"; 88?> 89--EXPECT-- 90*** Testing mb_regex_encoding() : usage variations *** 91 92-- Iteration 1 -- 93string(5) "UTF-8" 94bool(true) 95string(5) "UCS-4" 96 97-- Iteration 2 -- 98string(5) "UCS-4" 99mb_regex_encoding(): Argument #1 ($encoding) must be a valid encoding, "UCS-4BE" given 100string(5) "UCS-4" 101 102-- Iteration 3 -- 103string(5) "UCS-4" 104bool(true) 105string(7) "UCS-4LE" 106 107-- Iteration 4 -- 108string(7) "UCS-4LE" 109mb_regex_encoding(): Argument #1 ($encoding) must be a valid encoding, "UCS-2" given 110string(7) "UCS-4LE" 111 112-- Iteration 5 -- 113string(7) "UCS-4LE" 114mb_regex_encoding(): Argument #1 ($encoding) must be a valid encoding, "UCS-2BE" given 115string(7) "UCS-4LE" 116 117-- Iteration 6 -- 118string(7) "UCS-4LE" 119mb_regex_encoding(): Argument #1 ($encoding) must be a valid encoding, "UCS-2LE" given 120string(7) "UCS-4LE" 121 122-- Iteration 7 -- 123string(7) "UCS-4LE" 124bool(true) 125string(5) "UCS-4" 126 127-- Iteration 8 -- 128string(5) "UCS-4" 129bool(true) 130string(5) "UCS-4" 131 132-- Iteration 9 -- 133string(5) "UCS-4" 134bool(true) 135string(7) "UCS-4LE" 136 137-- Iteration 10 -- 138string(7) "UCS-4LE" 139bool(true) 140string(6) "UTF-16" 141 142-- Iteration 11 -- 143string(6) "UTF-16" 144bool(true) 145string(6) "UTF-16" 146 147-- Iteration 12 -- 148string(6) "UTF-16" 149bool(true) 150string(8) "UTF-16LE" 151 152-- Iteration 13 -- 153string(8) "UTF-16LE" 154mb_regex_encoding(): Argument #1 ($encoding) must be a valid encoding, "UTF-7" given 155string(8) "UTF-16LE" 156 157-- Iteration 14 -- 158string(8) "UTF-16LE" 159mb_regex_encoding(): Argument #1 ($encoding) must be a valid encoding, "UTF7-IMAP" given 160string(8) "UTF-16LE" 161 162-- Iteration 15 -- 163string(8) "UTF-16LE" 164bool(true) 165string(5) "UTF-8" 166 167-- Iteration 16 -- 168string(5) "UTF-8" 169bool(true) 170string(5) "ASCII" 171 172-- Iteration 17 -- 173string(5) "ASCII" 174bool(true) 175string(6) "EUC-JP" 176 177-- Iteration 18 -- 178string(6) "EUC-JP" 179bool(true) 180string(4) "SJIS" 181 182-- Iteration 19 -- 183string(4) "SJIS" 184bool(true) 185string(6) "EUC-JP" 186 187-- Iteration 20 -- 188string(6) "EUC-JP" 189bool(true) 190string(4) "SJIS" 191 192-- Iteration 21 -- 193string(4) "SJIS" 194mb_regex_encoding(): Argument #1 ($encoding) must be a valid encoding, "ISO-2022-JP" given 195string(4) "SJIS" 196 197-- Iteration 22 -- 198string(4) "SJIS" 199mb_regex_encoding(): Argument #1 ($encoding) must be a valid encoding, "JIS" given 200string(4) "SJIS" 201 202-- Iteration 23 -- 203string(4) "SJIS" 204bool(true) 205string(10) "ISO-8859-1" 206 207-- Iteration 24 -- 208string(10) "ISO-8859-1" 209bool(true) 210string(10) "ISO-8859-2" 211 212-- Iteration 25 -- 213string(10) "ISO-8859-2" 214bool(true) 215string(10) "ISO-8859-3" 216 217-- Iteration 26 -- 218string(10) "ISO-8859-3" 219bool(true) 220string(10) "ISO-8859-4" 221 222-- Iteration 27 -- 223string(10) "ISO-8859-4" 224bool(true) 225string(10) "ISO-8859-5" 226 227-- Iteration 28 -- 228string(10) "ISO-8859-5" 229bool(true) 230string(10) "ISO-8859-6" 231 232-- Iteration 29 -- 233string(10) "ISO-8859-6" 234bool(true) 235string(10) "ISO-8859-7" 236 237-- Iteration 30 -- 238string(10) "ISO-8859-7" 239bool(true) 240string(10) "ISO-8859-8" 241 242-- Iteration 31 -- 243string(10) "ISO-8859-8" 244bool(true) 245string(10) "ISO-8859-9" 246 247-- Iteration 32 -- 248string(10) "ISO-8859-9" 249bool(true) 250string(11) "ISO-8859-10" 251 252-- Iteration 33 -- 253string(11) "ISO-8859-10" 254bool(true) 255string(11) "ISO-8859-13" 256 257-- Iteration 34 -- 258string(11) "ISO-8859-13" 259bool(true) 260string(11) "ISO-8859-14" 261 262-- Iteration 35 -- 263string(11) "ISO-8859-14" 264bool(true) 265string(11) "ISO-8859-15" 266 267-- Iteration 36 -- 268string(11) "ISO-8859-15" 269mb_regex_encoding(): Argument #1 ($encoding) must be a valid encoding, "byte2be" given 270string(11) "ISO-8859-15" 271 272-- Iteration 37 -- 273string(11) "ISO-8859-15" 274mb_regex_encoding(): Argument #1 ($encoding) must be a valid encoding, "byte2le" given 275string(11) "ISO-8859-15" 276 277-- Iteration 38 -- 278string(11) "ISO-8859-15" 279mb_regex_encoding(): Argument #1 ($encoding) must be a valid encoding, "byte4be" given 280string(11) "ISO-8859-15" 281 282-- Iteration 39 -- 283string(11) "ISO-8859-15" 284mb_regex_encoding(): Argument #1 ($encoding) must be a valid encoding, "byte4le" given 285string(11) "ISO-8859-15" 286 287-- Iteration 40 -- 288string(11) "ISO-8859-15" 289mb_regex_encoding(): Argument #1 ($encoding) must be a valid encoding, "BASE64" given 290string(11) "ISO-8859-15" 291 292-- Iteration 41 -- 293string(11) "ISO-8859-15" 294mb_regex_encoding(): Argument #1 ($encoding) must be a valid encoding, "HTML-ENTITIES" given 295string(11) "ISO-8859-15" 296 297-- Iteration 42 -- 298string(11) "ISO-8859-15" 299mb_regex_encoding(): Argument #1 ($encoding) must be a valid encoding, "7bit" given 300string(11) "ISO-8859-15" 301 302-- Iteration 43 -- 303string(11) "ISO-8859-15" 304mb_regex_encoding(): Argument #1 ($encoding) must be a valid encoding, "8bit" given 305string(11) "ISO-8859-15" 306 307-- Iteration 44 -- 308string(11) "ISO-8859-15" 309bool(true) 310string(6) "EUC-CN" 311 312-- Iteration 45 -- 313string(6) "EUC-CN" 314mb_regex_encoding(): Argument #1 ($encoding) must be a valid encoding, "CP936" given 315string(6) "EUC-CN" 316 317-- Iteration 46 -- 318string(6) "EUC-CN" 319mb_regex_encoding(): Argument #1 ($encoding) must be a valid encoding, "HZ" given 320string(6) "EUC-CN" 321 322-- Iteration 47 -- 323string(6) "EUC-CN" 324bool(true) 325string(6) "EUC-TW" 326 327-- Iteration 48 -- 328string(6) "EUC-TW" 329mb_regex_encoding(): Argument #1 ($encoding) must be a valid encoding, "CP950" given 330string(6) "EUC-TW" 331 332-- Iteration 49 -- 333string(6) "EUC-TW" 334bool(true) 335string(4) "BIG5" 336 337-- Iteration 50 -- 338string(4) "BIG5" 339bool(true) 340string(6) "EUC-KR" 341 342-- Iteration 51 -- 343string(6) "EUC-KR" 344mb_regex_encoding(): Argument #1 ($encoding) must be a valid encoding, "UHC" given 345string(6) "EUC-KR" 346 347-- Iteration 52 -- 348string(6) "EUC-KR" 349mb_regex_encoding(): Argument #1 ($encoding) must be a valid encoding, "ISO-2022-KR" given 350string(6) "EUC-KR" 351 352-- Iteration 53 -- 353string(6) "EUC-KR" 354mb_regex_encoding(): Argument #1 ($encoding) must be a valid encoding, "Windows-1251" given 355string(6) "EUC-KR" 356 357-- Iteration 54 -- 358string(6) "EUC-KR" 359mb_regex_encoding(): Argument #1 ($encoding) must be a valid encoding, "Windows-1252" given 360string(6) "EUC-KR" 361 362-- Iteration 55 -- 363string(6) "EUC-KR" 364mb_regex_encoding(): Argument #1 ($encoding) must be a valid encoding, "CP866" given 365string(6) "EUC-KR" 366 367-- Iteration 56 -- 368string(6) "EUC-KR" 369bool(true) 370string(5) "KOI8R" 371Done 372