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