[ create a new paste ] login | about

Link: http://codepad.org/FBWMww7W    [ raw code | output | fork ]

PHP, pasted on May 23:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
    $string = "Hello";
    $string_length = strlen($string); // calculate the string length
    for($i=0;$i<$string_length;$i++){ 
        $current_ascii = ord($string{$i}); // convert to ascii code
        if($current_ascii>64 && $current_ascii<91){ //If Upper case
            $toggled_string .= chr($current_ascii+32); // Make lower case
            }elseif($current_ascii>96 && $current_ascii<123){ // If lower case
                $toggled_string .= chr($current_ascii-32); // Make Upper case
                }else{
                    $toggled_string .= $string{$i}; // Do Nothing
                }
            }
    echo "The toggled case letter for $string is  ".$toggled_string; // output will be hELLO
    ?>


Output:
1
The toggled case letter for Hello is  hELLO


Create a new paste based on this one


Comments: