1--TEST--
2Test iconv_substr() function : basic functionality
3--SKIPIF--
4<?php
5extension_loaded('iconv') or die('skip');
6function_exists('iconv_substr') or die("skip iconv_substr() is not available in this build");
7?>
8--INI--
9iconv.input_encoding=ISO-8859-1
10iconv.internal_encoding=ISO-8859-1
11iconv.output_encoding=ISO-8859-1
12--FILE--
13<?php
14/* Prototype  : string iconv_substr(string str, int offset, [int length, string charset])
15 * Description: Returns part of a string
16 * Source code: ext/iconv/iconv.c
17 */
18
19/*
20 * Test Basic Functionality of iconv_substr with ASCII characters and multibyte strings.
21 */
22
23echo "*** Testing iconv_substr() : basic functionality ***\n";
24
25$string_ascii = 'ABCDEF';
26//Japanese string in UTF-8
27$string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
28
29echo "\n-- ASCII string 1 --\n";
30var_dump(bin2hex(iconv_substr($string_ascii, 3)));
31
32echo "\n-- ASCII string 2 --\n";
33var_dump(bin2hex(iconv_substr($string_ascii, 3, 5, 'ISO-8859-1')));
34
35echo "\n-- Multibyte string 1 --\n";
36$result_1 = iconv_substr($string_mb, 2, 7);
37var_dump(bin2hex($result_1));
38
39echo "\n-- Multibyte string 2 --\n";
40$result_2 = iconv_substr($string_mb, 2, 7, 'utf-8');
41var_dump(bin2hex($result_2));
42
43echo "Done";
44?>
45--EXPECT--
46*** Testing iconv_substr() : basic functionality ***
47
48-- ASCII string 1 --
49string(6) "444546"
50
51-- ASCII string 2 --
52string(6) "444546"
53
54-- Multibyte string 1 --
55string(14) "a5e69cace8aa9e"
56
57-- Multibyte string 2 --
58string(42) "e8aa9ee38386e382ade382b9e38388e381a7e38199"
59Done
60