xref: /PHP-7.3/ext/iconv/tests/iconv_substr.phpt (revision 5088614e)
1--TEST--
2iconv_substr()
3--SKIPIF--
4<?php extension_loaded('iconv') or die('skip iconv extension is not available'); ?>
5--INI--
6iconv.internal_charset=ISO-8859-1
7--FILE--
8<?php
9function hexdump($str) {
10	$len = strlen($str);
11	for ($i = 0; $i < $len; ++$i) {
12		printf("%02x", ord($str[$i]));
13	}
14	print "\n";
15}
16
17function foo($str, $offset, $len, $charset) {
18	hexdump(substr($str, $offset, $len));
19	hexdump(iconv_substr($str, $offset, $len, $charset));
20}
21
22function bar($str, $offset, $len = false) {
23	if (is_bool($len)) {
24		var_dump(substr($str, $offset));
25		var_dump(iconv_substr($str, $offset));
26	} else {
27		var_dump(substr($str, $offset, $len));
28		var_dump(iconv_substr($str, $offset, $len));
29	}
30}
31
32foo("abcdefghijklmnopqrstuvwxyz", 5, 7, "ASCII");
33foo("��������������������������", 5, 7, "EUC-JP");
34bar("This is a test", 100000);
35bar("This is a test", 0, 100000);
36bar("This is a test", -3);
37bar("This is a test", 0, -9);
38bar("This is a test", 0, -100000);
39bar("This is a test", -9, -100000);
40var_dump(iconv("ISO-2022-JP", "EUC-JP", iconv_substr(iconv("EUC-JP", "ISO-2022-JP", "����ˤ��� ISO-2022-JP"), 3, 8, "ISO-2022-JP")));
41?>
42--EXPECT--
43666768696a6b6c
44666768696a6b6c
45a6a4a8a4aaa4ab
46a4aba4ada4afa4b1a4b3a4b5a4b7
47bool(false)
48bool(false)
49string(14) "This is a test"
50string(14) "This is a test"
51string(3) "est"
52string(3) "est"
53string(5) "This "
54string(5) "This "
55bool(false)
56bool(false)
57bool(false)
58bool(false)
59string(10) "���� ISO-2"
60