1--TEST-- 2Test strtolower() function 3--SKIPIF-- 4<?php 5if( 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*/ 22if( substr(PHP_OS, 0, 3) == 'WIN') { 23 setlocale(LC_ALL, 'C'); 24} else { 25 setlocale(LC_ALL, 'en_US.UTF-8'); 26} 27 28echo "*** Testing strtolower() with 128 chars ***\n"; 29for ($i=0; $i<=127; $i++){ 30 $char = chr($i); 31 print(bin2hex($char))." => ".(bin2hex(strtolower("$char")))."\n"; 32} 33 34echo "*** Testing strlower() with basic strings ***\n"; 35$str = "Mary Had A liTTle LAmb and ShE loveD IT So\n"; 36var_dump(strtolower($str)); 37 38echo "\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 array() 51); 52 53$count = 0; 54/* loop through to check possible variations */ 55foreach ($strings as $string) { 56 echo "\n-- Iteration $count --\n"; 57 var_dump( strtolower($string) ); 58 $count++; 59} 60 61echo "\n*** Testing strtolower() with two different case strings ***\n"; 62if (strtolower("HeLLo woRLd") === strtolower("hEllo WORLD")) 63 echo "strings are same, with Case Insensitive\n"; 64else 65 echo "strings are not same\n"; 66 67echo "\n*** Testing error conditions ***"; 68var_dump( strtolower() ); /* Zero arguments */ 69var_dump( strtolower("a", "b") ); /* Arguments > Expected */ 70 71echo "*** Done ***"; 72?> 73--EXPECTF-- 74*** Testing strtolower() with 128 chars *** 7500 => 00 7601 => 01 7702 => 02 7803 => 03 7904 => 04 8005 => 05 8106 => 06 8207 => 07 8308 => 08 8409 => 09 850a => 0a 860b => 0b 870c => 0c 880d => 0d 890e => 0e 900f => 0f 9110 => 10 9211 => 11 9312 => 12 9413 => 13 9514 => 14 9615 => 15 9716 => 16 9817 => 17 9918 => 18 10019 => 19 1011a => 1a 1021b => 1b 1031c => 1c 1041d => 1d 1051e => 1e 1061f => 1f 10720 => 20 10821 => 21 10922 => 22 11023 => 23 11124 => 24 11225 => 25 11326 => 26 11427 => 27 11528 => 28 11629 => 29 1172a => 2a 1182b => 2b 1192c => 2c 1202d => 2d 1212e => 2e 1222f => 2f 12330 => 30 12431 => 31 12532 => 32 12633 => 33 12734 => 34 12835 => 35 12936 => 36 13037 => 37 13138 => 38 13239 => 39 1333a => 3a 1343b => 3b 1353c => 3c 1363d => 3d 1373e => 3e 1383f => 3f 13940 => 40 14041 => 61 14142 => 62 14243 => 63 14344 => 64 14445 => 65 14546 => 66 14647 => 67 14748 => 68 14849 => 69 1494a => 6a 1504b => 6b 1514c => 6c 1524d => 6d 1534e => 6e 1544f => 6f 15550 => 70 15651 => 71 15752 => 72 15853 => 73 15954 => 74 16055 => 75 16156 => 76 16257 => 77 16358 => 78 16459 => 79 1655a => 7a 1665b => 5b 1675c => 5c 1685d => 5d 1695e => 5e 1705f => 5f 17160 => 60 17261 => 61 17362 => 62 17463 => 63 17564 => 64 17665 => 65 17766 => 66 17867 => 67 17968 => 68 18069 => 69 1816a => 6a 1826b => 6b 1836c => 6c 1846d => 6d 1856e => 6e 1866f => 6f 18770 => 70 18871 => 71 18972 => 72 19073 => 73 19174 => 74 19275 => 75 19376 => 76 19477 => 77 19578 => 78 19679 => 79 1977a => 7a 1987b => 7b 1997c => 7c 2007d => 7d 2017e => 7e 2027f => 7f 203*** Testing strlower() with basic strings *** 204string(43) "mary had a little lamb and she loved it so 205" 206 207*** Testing strtolower() with various strings *** 208-- Iteration 0 -- 209string(0) "" 210 211-- Iteration 1 -- 212string(6) "string" 213 214-- Iteration 2 -- 215string(10) "string0234" 216 217-- Iteration 3 -- 218string(20) "1.233.344string12333" 219 220-- Iteration 4 -- 221string(31) "$$$$$$!!!!@@@@@@@ abcdef !!!***" 222 223-- Iteration 5 -- 224string(13) "abcdabcdabcd" 225 226-- Iteration 6 -- 227string(0) "" 228 229-- Iteration 7 -- 230string(1) "1" 231 232-- Iteration 8 -- 233string(0) "" 234 235-- Iteration 9 -- 236 237Warning: strtolower() expects parameter 1 to be string, array given in %s on line %d 238NULL 239 240*** Testing strtolower() with two different case strings *** 241strings are same, with Case Insensitive 242 243*** Testing error conditions *** 244Warning: strtolower() expects exactly 1 parameter, 0 given in %s on line %d 245NULL 246 247Warning: strtolower() expects exactly 1 parameter, 2 given in %s on line %d 248NULL 249*** Done *** 250