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