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