1--TEST--
2Test mb_substr() function : usage variations - pass different integers to $start arg
3--SKIPIF--
4<?php
5extension_loaded('mbstring') or die('skip');
6function_exists('mb_substr') or die("skip mb_substr() is not available in this build");
7?>
8--FILE--
9<?php
10/* Prototype  : string mb_substr(string $str, int $start [, int $length [, string $encoding]])
11 * Description: Returns part of a string
12 * Source code: ext/mbstring/mbstring.c
13 */
14
15/*
16 * Test how mb_substr() behaves when passed a range of integers as $start argument
17 */
18
19echo "*** Testing mb_substr() : usage variations ***\n";
20
21mb_internal_encoding('UTF-8');
22
23$string_ascii = '+Is an English string'; //21 chars
24
25$string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII='); //21 chars
26
27/*
28 * Loop through integers as multiples of ten for $offset argument
29 * 60 is larger than *BYTE* count for $string_mb
30 */
31for ($i = -60; $i <= 60; $i += 10) {
32	if (@$a || @$b) {
33		$a = null;
34		$b = null;
35	}
36	echo "\n**-- Offset is: $i --**\n";
37	echo "-- ASCII String --\n";
38	$a = mb_substr($string_ascii, $i, 4);
39	if ($a !== false) {
40	   var_dump(bin2hex($a));
41	}
42	else {
43	   var_dump($a);
44	}
45	echo "--Multibyte String --\n";
46	$b = mb_substr($string_mb, $i, 4, 'UTF-8');
47	if (strlen($a) == mb_strlen($b, 'UTF-8')) { // should return same length
48		var_dump(bin2hex($b));
49	} else {
50		echo "Difference in length of ASCII string and multibyte string\n";
51	}
52
53}
54
55echo "Done";
56?>
57--EXPECT--
58*** Testing mb_substr() : usage variations ***
59
60**-- Offset is: -60 --**
61-- ASCII String --
62string(8) "2b497320"
63--Multibyte String --
64string(24) "e697a5e69cace8aa9ee38386"
65
66**-- Offset is: -50 --**
67-- ASCII String --
68string(8) "2b497320"
69--Multibyte String --
70string(24) "e697a5e69cace8aa9ee38386"
71
72**-- Offset is: -40 --**
73-- ASCII String --
74string(8) "2b497320"
75--Multibyte String --
76string(24) "e697a5e69cace8aa9ee38386"
77
78**-- Offset is: -30 --**
79-- ASCII String --
80string(8) "2b497320"
81--Multibyte String --
82string(24) "e697a5e69cace8aa9ee38386"
83
84**-- Offset is: -20 --**
85-- ASCII String --
86string(8) "49732061"
87--Multibyte String --
88string(24) "e69cace8aa9ee38386e382ad"
89
90**-- Offset is: -10 --**
91-- ASCII String --
92string(8) "69736820"
93--Multibyte String --
94string(8) "31323334"
95
96**-- Offset is: 0 --**
97-- ASCII String --
98string(8) "2b497320"
99--Multibyte String --
100string(24) "e697a5e69cace8aa9ee38386"
101
102**-- Offset is: 10 --**
103-- ASCII String --
104string(8) "6c697368"
105--Multibyte String --
106string(8) "30313233"
107
108**-- Offset is: 20 --**
109-- ASCII String --
110string(2) "67"
111--Multibyte String --
112string(6) "e38082"
113
114**-- Offset is: 30 --**
115-- ASCII String --
116string(0) ""
117--Multibyte String --
118string(0) ""
119
120**-- Offset is: 40 --**
121-- ASCII String --
122string(0) ""
123--Multibyte String --
124string(0) ""
125
126**-- Offset is: 50 --**
127-- ASCII String --
128string(0) ""
129--Multibyte String --
130string(0) ""
131
132**-- Offset is: 60 --**
133-- ASCII String --
134string(0) ""
135--Multibyte String --
136string(0) ""
137Done
138