Annotation of embedaddon/php/ext/mbstring/tests/mb_strlen.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: mb_strlen()
! 3: --SKIPIF--
! 4: <?php extension_loaded('mbstring') or die('skip mbstring not available'); ?>
! 5: --INI--
! 6: mbstring.func_overload=0
! 7: --FILE--
! 8: <?php
! 9: // TODO: Add more encodings
! 10:
! 11: //$debug=true;
! 12: ini_set('include_path', dirname(__FILE__));
! 13: include_once('common.inc');
! 14:
! 15: // restore detect_order to 'auto'
! 16: mb_detect_order('auto');
! 17:
! 18: // Test string
! 19: $euc_jp = '0123この文字列は日本語です。EUC-JPを使っています。0123日本語は面倒臭い。';
! 20: $ascii = 'abcdefghijklmnopqrstuvwxyz;]=#0123456789';
! 21:
! 22: // ASCII
! 23: echo "== ASCII ==\n";
! 24: print mb_strlen($ascii,'ASCII') . "\n";
! 25: print strlen($ascii) . "\n";
! 26:
! 27: // EUC-JP
! 28: echo "== EUC-JP ==\n";
! 29: print mb_strlen($euc_jp,'EUC-JP') . "\n";
! 30: mb_internal_encoding('EUC-JP') or print("mb_internal_encoding() failed\n");
! 31: print strlen($euc_jp) . "\n";
! 32:
! 33: // SJIS
! 34: echo "== SJIS ==\n";
! 35: $sjis = mb_convert_encoding($euc_jp, 'SJIS','EUC-JP');
! 36: print mb_strlen($sjis,'SJIS') . "\n";
! 37: mb_internal_encoding('SJIS') or print("mb_internal_encoding() failed\n");
! 38: print strlen($sjis) . "\n";
! 39:
! 40: // JIS
! 41: // Note: either convert_encoding or strlen has problem
! 42: echo "== JIS ==\n";
! 43: $jis = mb_convert_encoding($euc_jp, 'JIS','EUC-JP');
! 44: print mb_strlen($jis,'JIS') . "\n";
! 45: mb_internal_encoding('JIS') or print("mb_internal_encoding() failed\n");
! 46: print strlen($jis) . "\n";
! 47:
! 48: // UTF-8
! 49: // Note: either convert_encoding or strlen has problem
! 50: echo "== UTF-8 ==\n";
! 51: $utf8 = mb_convert_encoding($euc_jp, 'UTF-8','EUC-JP');
! 52: print mb_strlen($utf8,'UTF-8') . "\n";
! 53: mb_internal_encoding('UTF-8') or print("mb_internal_encoding() failed\n");
! 54: print strlen($utf8) . "\n";
! 55:
! 56:
! 57: // Wrong Parameters
! 58: echo "== WRONG PARAMETERS ==\n";
! 59: // Array
! 60: // Note: PHP Warning, strlen() expects parameter 1 to be string, array given
! 61: $r = strlen($t_ary);
! 62: echo $r."\n";
! 63: // Object
! 64: // Note: PHP Warning, strlen() expects parameter 1 to be string, object given
! 65: $r = strlen($t_obj);
! 66: echo $r."\n";
! 67: // Wrong encoding
! 68: mb_internal_encoding('EUC-JP');
! 69: $r = mb_strlen($euc_jp, 'BAD_NAME');
! 70: echo $r."\n";
! 71:
! 72:
! 73:
! 74:
! 75: ?>
! 76:
! 77: --EXPECT--
! 78: == ASCII ==
! 79: 40
! 80: 40
! 81: == EUC-JP ==
! 82: 43
! 83: 72
! 84: == SJIS ==
! 85: 43
! 86: 72
! 87: == JIS ==
! 88: 43
! 89: 90
! 90: == UTF-8 ==
! 91: 43
! 92: 101
! 93: == WRONG PARAMETERS ==
! 94: ERR: Warning
! 95:
! 96: ERR: Warning
! 97:
! 98: ERR: Warning
! 99:
! 100:
! 101:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>