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    var_dump(base64_encode($a));
32    echo "--Multibyte String --\n";
33    $b = mb_substr($string_mb, $i, 4, 'UTF-8');
34    if (strlen($a) == mb_strlen($b, 'UTF-8')) { // should return same length
35        var_dump(base64_encode($b));
36    } else {
37        echo "Difference in length of ASCII string and multibyte string\n";
38    }
39
40}
41
42echo "Done";
43?>
44--EXPECT--
45*** Testing mb_substr() : usage variations ***
46
47**-- Offset is: -60 --**
48-- ASCII String --
49string(8) "K0lzIA=="
50--Multibyte String --
51string(16) "5pel5pys6Kqe44OG"
52
53**-- Offset is: -50 --**
54-- ASCII String --
55string(8) "K0lzIA=="
56--Multibyte String --
57string(16) "5pel5pys6Kqe44OG"
58
59**-- Offset is: -40 --**
60-- ASCII String --
61string(8) "K0lzIA=="
62--Multibyte String --
63string(16) "5pel5pys6Kqe44OG"
64
65**-- Offset is: -30 --**
66-- ASCII String --
67string(8) "K0lzIA=="
68--Multibyte String --
69string(16) "5pel5pys6Kqe44OG"
70
71**-- Offset is: -20 --**
72-- ASCII String --
73string(8) "SXMgYQ=="
74--Multibyte String --
75string(16) "5pys6Kqe44OG44Kt"
76
77**-- Offset is: -10 --**
78-- ASCII String --
79string(8) "aXNoIA=="
80--Multibyte String --
81string(8) "MTIzNA=="
82
83**-- Offset is: 0 --**
84-- ASCII String --
85string(8) "K0lzIA=="
86--Multibyte String --
87string(16) "5pel5pys6Kqe44OG"
88
89**-- Offset is: 10 --**
90-- ASCII String --
91string(8) "bGlzaA=="
92--Multibyte String --
93string(8) "MDEyMw=="
94
95**-- Offset is: 20 --**
96-- ASCII String --
97string(4) "Zw=="
98--Multibyte String --
99string(4) "44CC"
100
101**-- Offset is: 30 --**
102-- ASCII String --
103string(0) ""
104--Multibyte String --
105string(0) ""
106
107**-- Offset is: 40 --**
108-- ASCII String --
109string(0) ""
110--Multibyte String --
111string(0) ""
112
113**-- Offset is: 50 --**
114-- ASCII String --
115string(0) ""
116--Multibyte String --
117string(0) ""
118
119**-- Offset is: 60 --**
120-- ASCII String --
121string(0) ""
122--Multibyte String --
123string(0) ""
124Done
125