]> granicus.if.org Git - php/blob
041b66a00c
[php] /
1 --TEST--
2 Test strtolower() 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 strtolower ( string $str );
19    Description:
20      Returns string with all alphabetic characters converted to lowercase.
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 strtolower() with 128 chars ***\n";
29 for ($i=0; $i<=127; $i++){
30   $char = chr($i);
31   print(bin2hex($char))." => ".(bin2hex(strtolower("$char")))."\n";
32 }
33
34 echo "*** Testing strlower() with basic strings ***\n";
35 $str = "Mary Had A liTTle LAmb and ShE loveD IT So\n";
36 var_dump(strtolower($str));
37
38 echo "\n*** Testing strtolower() with various strings ***";
39 /* strings to pass strtolower() */
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( strtolower($string) );
57   $count++;
58 }
59
60 echo "\n*** Testing strtolower() with two different case strings ***\n";
61 if (strtolower("HeLLo woRLd") === strtolower("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 strtolower() 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 => 61
136 42 => 62
137 43 => 63
138 44 => 64
139 45 => 65
140 46 => 66
141 47 => 67
142 48 => 68
143 49 => 69
144 4a => 6a
145 4b => 6b
146 4c => 6c
147 4d => 6d
148 4e => 6e
149 4f => 6f
150 50 => 70
151 51 => 71
152 52 => 72
153 53 => 73
154 54 => 74
155 55 => 75
156 56 => 76
157 57 => 77
158 58 => 78
159 59 => 79
160 5a => 7a
161 5b => 5b
162 5c => 5c
163 5d => 5d
164 5e => 5e
165 5f => 5f
166 60 => 60
167 61 => 61
168 62 => 62
169 63 => 63
170 64 => 64
171 65 => 65
172 66 => 66
173 67 => 67
174 68 => 68
175 69 => 69
176 6a => 6a
177 6b => 6b
178 6c => 6c
179 6d => 6d
180 6e => 6e
181 6f => 6f
182 70 => 70
183 71 => 71
184 72 => 72
185 73 => 73
186 74 => 74
187 75 => 75
188 76 => 76
189 77 => 77
190 78 => 78
191 79 => 79
192 7a => 7a
193 7b => 7b
194 7c => 7c
195 7d => 7d
196 7e => 7e
197 7f => 7f
198 *** Testing strlower() with basic strings ***
199 string(43) "mary had a little lamb and she loved it so
200 "
201
202 *** Testing strtolower() with various strings ***
203 -- Iteration 0 --
204 string(0) ""
205
206 -- Iteration 1 --
207 string(6) "string"
208
209 -- Iteration 2 --
210 string(10) "string0234"
211
212 -- Iteration 3 --
213 string(20) "1.233.344string12333"
214
215 -- Iteration 4 --
216 string(31) "$$$$$$!!!!@@@@@@@ abcdef !!!***"
217
218 -- Iteration 5 --
219 string(13) "abcd\0abcdabcd"
220
221 -- Iteration 6 --
222 string(0) ""
223
224 -- Iteration 7 --
225 string(1) "1"
226
227 -- Iteration 8 --
228 string(0) ""
229
230 *** Testing strtolower() with two different case strings ***
231 strings are same, with Case Insensitive
232 *** Done ***