'Convert string to lowercase AND then convert it to its original form in PHP, is it possible?
I need to convert input data to lower and then return it in it's original form with PHP, is it impossible or does anyone have a solution? thank you.
ps, i'm sorry if there is another thread about this subject but i havn't found one.
function getdatalanguage($data){
$data = replacequote($data);
$data = replacecolon($data);
$data = strtolower($data);
$startlang = "språk";
$endlang = "datum";
$datalang = getBetween($event1,$startlang,$endlang);
$startlang1 = ">";
$endlang1 = "<";
$datatlang = getBetween($datalang,$startlang1,$endlang1);
return $datalang;
}
the data I convert to lower could be like "Hello hOw ARE yOU tOdAy" then i make it all to lower to make it more flexible to get the data i want to fetch but then i want to show it like "Hello hOw ARE yOU tOdAy" again.
EDIT: If anyone wonders how I solved the problem I used str_ireplace method like $a=str_ireplace("hElLo","hello",$a)
Solution 1:[1]
"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.
Solution 2:[2]
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.
Solution 3:[3]
If anyone wonders how I solved the problem I used str_ireplace method like $a=str_ireplace("hElLo","hello",$a)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | LucasM |
Solution 3 | Dmitrilen |