]> granicus.if.org Git - php/blob
6c7434ba16
[php] /
1 --TEST--
2 Test strtoupper() function
3 --SKIPIF--
4 <?php
5 if( substr(PHP_OS, 0, 3) == 'WIN') {
6   if (!setlocale(LC_ALL, 'C')) {
7     die('skip need "C" locale (this windows is broken)');
8   }
9 } else {
10   if (!setlocale(LC_ALL, 'en_US.UTF-8', 'en')) {
11     die('skip need "en_US.UTF-8" locale');
12   }
13 }
14 ?>
15 --FILE--
16 <?php
17 /* Prototype:
18      string strtoupper ( string $string );
19    Description:
20      Returns string with all alphabetic characters converted to uppercase
21 */
22 if( substr(PHP_OS, 0, 3) == 'WIN') {
23   setlocale(LC_ALL, 'C');
24 } else {
25   setlocale(LC_ALL, 'en_US.UTF-8');
26 }
27
28 echo "*** Testing strtoupper() with 128 chars ***\n";
29 for ($i=0; $i<=127; $i++){
30   $char = chr($i);
31   print(bin2hex($char))." => ".(bin2hex(strtoupper("$char")))."\n";
32 }
33
34 echo "\n*** Testing strtoupper() with basic strings ***\n";
35 $str = "Mary Had A liTTle LAmb and ShE loveD IT So\n";
36 var_dump(strtoupper($str));
37
38 echo "\n*** Testing strtoupper() with various strings ***";
39 /* strings to pass strtoupper() */
40 $strings = array (
41   "",
42   "string",
43   "stRINg0234",
44   "1.233.344StrinG12333",
45   "$$$$$$!!!!@@@@@@@ ABCDEF !!!***",
46   "ABCD\0abcdABCD",
47   NULL,
48   TRUE,
49   FALSE,
50 );
51
52 $count = 0;
53 /* loop through to check possible variations */
54 foreach ($strings as $string) {
55   echo "\n-- Iteration $count --\n";
56   var_dump( strtoupper($string) );
57   $count++;
58 }
59
60 echo "\n*** Testing strtoupper() with two different case strings ***\n";
61 if (strtoupper("HeLLo woRLd") === strtoupper("hEllo WORLD"))
62   echo "strings are same, with Case Insensitive\n";
63 else
64   echo "strings are not same\n";
65
66 echo "*** Done ***";
67 ?>
68 --EXPECT--
69 *** Testing strtoupper() with 128 chars ***
70 00 => 00
71 01 => 01
72 02 => 02
73 03 => 03
74 04 => 04
75 05 => 05
76 06 => 06
77 07 => 07
78 08 => 08
79 09 => 09
80 0a => 0a
81 0b => 0b
82 0c => 0c
83 0d => 0d
84 0e => 0e
85 0f => 0f
86 10 => 10
87 11 => 11
88 12 => 12
89 13 => 13
90 14 => 14
91 15 => 15
92 16 => 16
93 17 => 17
94 18 => 18
95 19 => 19
96 1a => 1a
97 1b => 1b
98 1c => 1c
99 1d => 1d
100 1e => 1e
101 1f => 1f
102 20 => 20
103 21 => 21
104 22 => 22
105 23 => 23
106 24 => 24
107 25 => 25
108 26 => 26
109 27 => 27
110 28 => 28
111 29 => 29
112 2a => 2a
113 2b => 2b
114 2c => 2c
115 2d => 2d
116 2e => 2e
117 2f => 2f
118 30 => 30
119 31 => 31
120 32 => 32
121 33 => 33
122 34 => 34
123 35 => 35
124 36 => 36
125 37 => 37
126 38 => 38
127 39 => 39
128 3a => 3a
129 3b => 3b
130 3c => 3c
131 3d => 3d
132 3e => 3e
133 3f => 3f
134 40 => 40
135 41 => 41
136 42 => 42
137 43 => 43
138 44 => 44
139 45 => 45
140 46 => 46
141 47 => 47
142 48 => 48
143 49 => 49
144 4a => 4a
145 4b => 4b
146 4c => 4c
147 4d => 4d
148 4e => 4e
149 4f => 4f
150 50 => 50
151 51 => 51
152 52 => 52
153 53 => 53
154 54 => 54
155 55 => 55
156 56 => 56
157 57 => 57
158 58 => 58
159 59 => 59
160 5a => 5a
161 5b => 5b
162 5c => 5c
163 5d => 5d
164 5e => 5e
165 5f => 5f
166 60 => 60
167 61 => 41
168 62 => 42
169 63 => 43
170 64 => 44
171 65 => 45
172 66 => 46
173 67 => 47
174 68 => 48
175 69 => 49
176 6a => 4a
177 6b => 4b
178 6c => 4c
179 6d => 4d
180 6e => 4e
181 6f => 4f
182 70 => 50
183 71 => 51
184 72 => 52
185 73 => 53
186 74 => 54
187 75 => 55
188 76 => 56
189 77 => 57
190 78 => 58
191 79 => 59
192 7a => 5a
193 7b => 7b
194 7c => 7c
195 7d => 7d
196 7e => 7e
197 7f => 7f
198
199 *** Testing strtoupper() with basic strings ***
200 string(43) "MARY HAD A LITTLE LAMB AND SHE LOVED IT SO
201 "
202
203 *** Testing strtoupper() with various strings ***
204 -- Iteration 0 --
205 string(0) ""
206
207 -- Iteration 1 --
208 string(6) "STRING"
209
210 -- Iteration 2 --
211 string(10) "STRING0234"
212
213 -- Iteration 3 --
214 string(20) "1.233.344STRING12333"
215
216 -- Iteration 4 --
217 string(31) "$$$$$$!!!!@@@@@@@ ABCDEF !!!***"
218
219 -- Iteration 5 --
220 string(13) "ABCD\0ABCDABCD"
221
222 -- Iteration 6 --
223 string(0) ""
224
225 -- Iteration 7 --
226 string(1) "1"
227
228 -- Iteration 8 --
229 string(0) ""
230
231 *** Testing strtoupper() with two different case strings ***
232 strings are same, with Case Insensitive
233 *** Done ***