xref: /PHP-5.4/ext/mbstring/tests/mb_substr.phpt (revision 4a78652f)
1--TEST--
2mb_substr()
3--SKIPIF--
4<?php extension_loaded('mbstring') or die('skip mbstring not available'); ?>
5--INI--
6output_handler=
7mbstring.func_overload=0
8--FILE--
9<?php
10// TODO: Add more encodings
11ini_set('include_path','.');
12include_once('common.inc');
13
14// EUC-JP
15$euc_jp = b'0123����ʸ��������ܸ�Ǥ���EUC-JP��ȤäƤ��ޤ������ܸ�����ݽ�����';
16
17print  "1: ". bin2hex(mb_substr($euc_jp,  10,  10,'EUC-JP')) . "\n";
18print  "2: ". bin2hex(mb_substr($euc_jp,   0, 100,'EUC-JP')) . "\n";
19
20$str = mb_substr($euc_jp, 100, 10,'EUC-JP');
21// Note: returns last character
22($str === "") ? print "3 OK\n" : print "NG: ".bin2hex($str)."\n";
23
24$str = mb_substr($euc_jp, -100, 10,'EUC-JP');
25($str !== "") ? print "4 OK: ".bin2hex($str)."\n" : print "NG: ".bin2hex($str)."\n";
26
27?>
28
29--EXPECT--
301: c6fccbdcb8eca4c7a4b9a1a34555432d
312: 30313233a4b3a4cecab8bbfacef3a4cfc6fccbdcb8eca4c7a4b9a1a34555432d4a50a4f2bbc8a4c3a4c6a4a4a4dea4b9a1a3c6fccbdcb8eca4cfccccc5ddbdada4a4a1a3
323 OK
334 OK: 30313233a4b3a4cecab8bbfacef3a4cf
34
35
36