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