xref: /PHP-7.0/ext/mbstring/tests/mb_strlen.phpt (revision 85d77510)
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
77--EXPECT--
78== ASCII ==
7940
8040
81== EUC-JP ==
8243
8372
84== SJIS ==
8543
8672
87== JIS ==
8843
8990
90== UTF-8 ==
9143
92101
93== WRONG PARAMETERS ==
94ERR: Warning
95
96ERR: Warning
97
98ERR: Warning
99
100
101
102