xref: /PHP-7.4/ext/mbstring/tests/mb_strlen.phpt (revision 26dfce7f)
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
11ini_set('include_path', __DIR__);
12include_once('common.inc');
13
14// restore detect_order to 'auto'
15mb_detect_order('auto');
16
17// Test string
18$euc_jp = '0123����ʸ��������ܸ�Ǥ���EUC-JP��ȤäƤ��ޤ���0123���ܸ�����ݽ�����';
19$ascii  = 'abcdefghijklmnopqrstuvwxyz;]=#0123456789';
20
21// ASCII
22echo "== ASCII ==\n";
23print  mb_strlen($ascii,'ASCII') . "\n";
24print  strlen($ascii) . "\n";
25
26// EUC-JP
27echo "== EUC-JP ==\n";
28print  mb_strlen($euc_jp,'EUC-JP') . "\n";
29mb_internal_encoding('EUC-JP') or print("mb_internal_encoding() failed\n");
30print  strlen($euc_jp) . "\n";
31
32// SJIS
33echo "== SJIS ==\n";
34$sjis = mb_convert_encoding($euc_jp, 'SJIS','EUC-JP');
35print  mb_strlen($sjis,'SJIS') . "\n";
36mb_internal_encoding('SJIS') or print("mb_internal_encoding() failed\n");
37print  strlen($sjis) . "\n";
38
39// JIS
40// Note: either convert_encoding or strlen has problem
41echo "== JIS ==\n";
42$jis = mb_convert_encoding($euc_jp, 'JIS','EUC-JP');
43print  mb_strlen($jis,'JIS') . "\n";
44mb_internal_encoding('JIS')  or print("mb_internal_encoding() failed\n");
45print  strlen($jis) . "\n";
46
47// UTF-8
48// Note: either convert_encoding or strlen has problem
49echo "== UTF-8 ==\n";
50$utf8 = mb_convert_encoding($euc_jp, 'UTF-8','EUC-JP');
51print  mb_strlen($utf8,'UTF-8') . "\n";
52mb_internal_encoding('UTF-8')  or print("mb_internal_encoding() failed\n");
53print  strlen($utf8) . "\n";
54
55
56// Wrong Parameters
57echo "== WRONG PARAMETERS ==\n";
58// Array
59// Note: PHP Warning, strlen() expects parameter 1 to be string, array given
60$r = strlen($t_ary);
61echo $r."\n";
62// Object
63// Note: PHP Warning, strlen() expects parameter 1 to be string, object given
64$r = strlen($t_obj);
65echo $r."\n";
66// Wrong encoding
67mb_internal_encoding('EUC-JP');
68$r = mb_strlen($euc_jp, 'BAD_NAME');
69echo $r."\n";
70
71
72?>
73--EXPECTF--
74== ASCII ==
7540
7640
77== EUC-JP ==
7843
7972
80== SJIS ==
8143
8272
83== JIS ==
8443
8590
86== UTF-8 ==
8743
88101
89== WRONG PARAMETERS ==
90
91Warning: strlen() expects parameter 1 to be string, array given in %s on line %d
92
93
94Warning: strlen() expects parameter 1 to be string, object given in %s on line %d
95
96
97Warning: mb_strlen(): Unknown encoding "BAD_NAME" in %s on line %d
98