"or does anyone have a solution?"
^ By that, I take it you might be looking for an alternate solution.
In order to keep the original value, you can assign it to a variable, and use strtolower() to make it lowercase, then strtoupper() to make it uppercase.
echo $original_string = "ORIGINAL UPPER CASE STRING and Camel Case or mIXed cASe";
echo "<br>";
echo $lowercased_string = strtolower($original_string) . " this has been converted.";
echo "<br>";
echo "The below is now in uppercase.";
echo "<br>";
echo $modified_string = strtoupper($original_string);
echo "<br>";
$var = $original_string . " is the original value.";
echo $var;
Note: Echoing an assigned variable is perfectly valid. You can remove those as needed.
The above will print:
ORIGINAL UPPER CASE STRING and Camel Case or mIXed cASe original upper case string and camel case or mixed case this has been converted. The below is now in uppercase. ORIGINAL UPPER CASE STRING AND CAMEL CASE OR MIXED CASE ORIGINAL UPPER CASE STRING and Camel Case or mIXed cASe is the original value.Answer from Funk Forty Niner on Stack Overflow
How to make the first character lowercase only?
$text = 'Hello';
$text[0] = strtolower($text[0]);
That changes only the first character.What is the opposite of strtolower()?
Does strtolower() affect numbers?
"or does anyone have a solution?"
^ By that, I take it you might be looking for an alternate solution.
In order to keep the original value, you can assign it to a variable, and use strtolower() to make it lowercase, then strtoupper() to make it uppercase.
echo $original_string = "ORIGINAL UPPER CASE STRING and Camel Case or mIXed cASe";
echo "<br>";
echo $lowercased_string = strtolower($original_string) . " this has been converted.";
echo "<br>";
echo "The below is now in uppercase.";
echo "<br>";
echo $modified_string = strtoupper($original_string);
echo "<br>";
$var = $original_string . " is the original value.";
echo $var;
Note: Echoing an assigned variable is perfectly valid. You can remove those as needed.
The above will print:
ORIGINAL UPPER CASE STRING and Camel Case or mIXed cASe original upper case string and camel case or mixed case this has been converted. The below is now in uppercase. ORIGINAL UPPER CASE STRING AND CAMEL CASE OR MIXED CASE ORIGINAL UPPER CASE STRING and Camel Case or mIXed cASe is the original value.
So you want something like this?
echo strtolower("THIS WILL ALL BE LOWERCASE.");
and for making it all cap again (upper) do
echo strtoupper("this will all be upper case");
So you can take the input as strtolower, then in your return, lets say to save to a DB, send it in a strtoupper. Hope that helps, if not please explain an example case.
If you want to change the case of the entire string, try: strtoupper( $string ) or strtolower( $string ). If you want to change just the case of the first letter of the string, try: ucfirst( $string) or lcfirst( $string ).
There is also str_replace(), which is case-sensitive. You could do something like str_replace( 'a', 'A', $string ); to replace all lowercase letter 'a' with uppercase letter 'A'.
You may want to have a look at a list of the php string functions.
It looks like your trying to invert the case ?
$word = strtolower($word) ^ strtoupper($word) ^ $word;