Created
June 29, 2015 04:02
-
-
Save oceanapplications/44d69d83971d3248b60a to your computer and use it in GitHub Desktop.
String case inversion script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Version 1, simple and performs about 40 times better than version 2 | |
$input = "i FORGOT CAPLOCK"; | |
$output = ""; | |
foreach(str_split($input) as $letter) | |
{ | |
if(ctype_upper($letter)) | |
{ $output .= strtolower($letter);} | |
else { $output .= strtoupper($letter); } | |
} | |
echo $output; | |
//Version 2, not really a lot of point to it, it's slow and more complicated | |
$text = str_split("i FORGOT CAPLOCK"); | |
foreach($text as $position => $input) | |
{ | |
if(ctype_upper($input)) | |
{ $text[$position] = strtolower($input);} | |
else { $text[$position] = strtoupper($input); } | |
} | |
echo implode($text); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment