php-src/ext/mbstring/tests/mb_strlen.phpt

103 lines
2.0 KiB
Plaintext
Raw Normal View History

2002-10-21 19:19:05 +00:00
--TEST--
mb_strlen()
--SKIPIF--
2002-10-30 08:06:52 +00:00
<?php extension_loaded('mbstring') or die('skip mbstring not available'); ?>
--INI--
mbstring.func_overload=0
2002-10-21 19:19:05 +00:00
--FILE--
2002-03-02 10:44:57 +00:00
<?php
// TODO: Add more encodings
//$debug=true;
ini_set('include_path','.');
include_once('common.inc');
2002-03-02 10:44:57 +00:00
// restore detect_order to 'auto'
mb_detect_order('auto');
// Test string
$euc_jp = '0123<32><33><EFBFBD><EFBFBD>ʸ<EFBFBD><CAB8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܸ<EFBFBD><DCB8>Ǥ<EFBFBD><C7A4><EFBFBD>EUC-JP<4A><50><EFBFBD>ȤäƤ<C3A4><C6A4>ޤ<EFBFBD><DEA4><EFBFBD>0123<32><33><EFBFBD>ܸ<EFBFBD><DCB8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD><EFBFBD><EFBFBD><EFBFBD>';
$ascii = 'abcdefghijklmnopqrstuvwxyz;]=#0123456789';
// ASCII
echo "== ASCII ==\n";
2006-07-29 17:09:59 +00:00
print mb_strlen($ascii,'ASCII') . "\n";
2002-03-02 10:44:57 +00:00
print strlen($ascii) . "\n";
// EUC-JP
echo "== EUC-JP ==\n";
2006-07-29 17:09:59 +00:00
print mb_strlen($euc_jp,'EUC-JP') . "\n";
2002-03-02 10:44:57 +00:00
mb_internal_encoding('EUC-JP') or print("mb_internal_encoding() failed\n");
print strlen($euc_jp) . "\n";
// SJIS
echo "== SJIS ==\n";
2006-07-29 17:09:59 +00:00
$sjis = mb_convert_encoding($euc_jp, 'SJIS','EUC-JP');
print mb_strlen($sjis,'SJIS') . "\n";
2002-03-02 10:44:57 +00:00
mb_internal_encoding('SJIS') or print("mb_internal_encoding() failed\n");
print strlen($sjis) . "\n";
// JIS
// Note: either convert_encoding or strlen has problem
echo "== JIS ==\n";
2006-07-29 17:09:59 +00:00
$jis = mb_convert_encoding($euc_jp, 'JIS','EUC-JP');
print mb_strlen($jis,'JIS') . "\n";
2002-03-02 10:44:57 +00:00
mb_internal_encoding('JIS') or print("mb_internal_encoding() failed\n");
print strlen($jis) . "\n";
// UTF-8
// Note: either convert_encoding or strlen has problem
echo "== UTF-8 ==\n";
2006-07-29 17:09:59 +00:00
$utf8 = mb_convert_encoding($euc_jp, 'UTF-8','EUC-JP');
print mb_strlen($utf8,'UTF-8') . "\n";
2002-03-02 10:44:57 +00:00
mb_internal_encoding('UTF-8') or print("mb_internal_encoding() failed\n");
print strlen($utf8) . "\n";
// Wrong Parameters
echo "== WRONG PARAMETERS ==\n";
// Array
// Note: PHP Notice, but returns some value
$r = strlen($t_ary);
echo $r."\n";
// Object
2006-07-29 17:09:59 +00:00
// Note: PHP Notice, but returns some value
2002-03-02 10:44:57 +00:00
$r = strlen($t_obj);
echo $r."\n";
// Wrong encoding
mb_internal_encoding('EUC-JP');
2006-07-29 17:09:59 +00:00
$r = mb_strlen($euc_jp, 'BAD_NAME');
2002-03-02 10:44:57 +00:00
echo $r."\n";
2006-07-29 17:09:59 +00:00
2002-03-02 10:44:57 +00:00
?>
2002-10-21 19:19:05 +00:00
--EXPECT--
== ASCII ==
2006-07-29 17:09:59 +00:00
40
2002-10-21 19:19:05 +00:00
40
== EUC-JP ==
2006-07-29 17:09:59 +00:00
43
2002-10-21 19:19:05 +00:00
72
== SJIS ==
2006-07-29 17:09:59 +00:00
43
2002-10-21 19:19:05 +00:00
72
== JIS ==
2006-07-29 17:09:59 +00:00
43
90
2002-10-21 19:19:05 +00:00
== UTF-8 ==
2006-07-29 17:09:59 +00:00
43
101
2002-10-21 19:19:05 +00:00
== WRONG PARAMETERS ==
ERR: Notice
5
2006-01-19 20:52:45 +00:00
ERR: Catchable fatal error
2002-10-21 19:19:05 +00:00
ERR: Notice
6
ERR: Warning
2006-07-29 17:09:59 +00:00