String Case conversion

String Case conversion

<?php

function string_inverse_string($str)

{

//Make everything uppercase, and then compare

$new = strtoupper( $str );

 

//split into arrays

$s = str_split( $str );

$n = str_split( $new );

 

//now we step through each letter, and if its the same as before, we swap it out

for ($i = 0; $i < count($s); $i++)

{

//If the letters are identical, then it was already uppercase, so make it lowercase

if ( $s[$i] === $n[$i] ) { $n[$i] = strtolower($n[$i]); }

}

//join the new string back together

$newstr = implode(”", $n);

return $newstr;

}

$input = “This Is Test String”;

$inv = string_inverse_string($input);

?>

The above String_inverse_case() funtion is used to convert the lower case letters into upper case and upper case letters into lower case letters.

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.