xref: /PHP-7.2/ext/mbstring/tests/mb_strlen.phpt (revision f1d7e3ca)
1--TEST--
2mb_strlen()
3--SKIPIF--
4<?php extension_loaded('mbstring') or die('skip mbstring not available'); ?>
5--INI--
6mbstring.func_overload=0
7--FILE--
8<?php
9// TODO: Add more encodings
10
11//$debug=true;
12ini_set('include_path', dirname(__FILE__));
13include_once('common.inc');
14
15// restore detect_order to 'auto'
16mb_detect_order('auto');
17
18// Test string
19$euc_jp = '0123����ʸ��������ܸ�Ǥ���EUC-JP��ȤäƤ��ޤ���0123���ܸ�����ݽ�����';
20$ascii  = 'abcdefghijklmnopqrstuvwxyz;]=#0123456789';
21
22// ASCII
23echo "== ASCII ==\n";
24print  mb_strlen($ascii,'ASCII') . "\n";
25print  strlen($ascii) . "\n";
26
27// EUC-JP
28echo "== EUC-JP ==\n";
29print  mb_strlen($euc_jp,'EUC-JP') . "\n";
30mb_internal_encoding('EUC-JP') or print("mb_internal_encoding() failed\n");
31print  strlen($euc_jp) . "\n";
32
33// SJIS
34echo "== SJIS ==\n";
35$sjis = mb_convert_encoding($euc_jp, 'SJIS','EUC-JP');
36print  mb_strlen($sjis,'SJIS') . "\n";
37mb_internal_encoding('SJIS') or print("mb_internal_encoding() failed\n");
38print  strlen($sjis) . "\n";
39
40// JIS
41// Note: either convert_encoding or strlen has problem
42echo "== JIS ==\n";
43$jis = mb_convert_encoding($euc_jp, 'JIS','EUC-JP');
44print  mb_strlen($jis,'JIS') . "\n";
45mb_internal_encoding('JIS')  or print("mb_internal_encoding() failed\n");
46print  strlen($jis) . "\n";
47
48// UTF-8
49// Note: either convert_encoding or strlen has problem
50echo "== UTF-8 ==\n";
51$utf8 = mb_convert_encoding($euc_jp, 'UTF-8','EUC-JP');
52print  mb_strlen($utf8,'UTF-8') . "\n";
53mb_internal_encoding('UTF-8')  or print("mb_internal_encoding() failed\n");
54print  strlen($utf8) . "\n";
55
56
57// Wrong Parameters
58echo "== WRONG PARAMETERS ==\n";
59// Array
60// Note: PHP Warning, strlen() expects parameter 1 to be string, array given
61$r = strlen($t_ary);
62echo $r."\n";
63// Object
64// Note: PHP Warning, strlen() expects parameter 1 to be string, object given
65$r = strlen($t_obj);
66echo $r."\n";
67// Wrong encoding
68mb_internal_encoding('EUC-JP');
69$r = mb_strlen($euc_jp, 'BAD_NAME');
70echo $r."\n";
71
72
73
74
75?>
76--EXPECT--
77== ASCII ==
7840
7940
80== EUC-JP ==
8143
8272
83== SJIS ==
8443
8572
86== JIS ==
8743
8890
89== UTF-8 ==
9043
91101
92== WRONG PARAMETERS ==
93ERR: Warning
94
95ERR: Warning
96
97ERR: Warning
98