Inverse for strtolower
Script turns Barak Obama president
to barak obama president
through strtolower()
.
How to turn it back to Barak Obama president
?
Want to inverse strtolower()
effect withour chang开发者_如何学JAVAing core script.
You can't do that unless you teach PHP to speak the English language. ucwords will capitalize every word, but it can't possibly know which words should be capitalized if the information from the original string has been lost.
You can't. It's not reversible. How would the function know that the first two words should be capitalized but not the third?
(Well, if you can figure that problem out, then sure you can, but it's not trivial. Figuring out how to handle "LeBron James" is just the beginning of your headaches.)
Store the lowercase string in a separate variable to retain the original string.
You need to rephase your question to get a solution.
ToLower is just going to convert everything to lower case, and ToUpper just converts everything to upper case. It does not care for the input it just enures the output is all lower case. So logically its not possible.
If instead your method was written to make only the first letter of a word lower case, then the inverse is to make only the first letter of a word upper case.
So making everything lower case, the inverse is to make it upper case. Turning it back to the original string is not a reverse of the method. As such i would recommend you either just store the original string, or work out what is your suitable inverse I.e. ucfirst($string) against lcfirst($string).
ucfirst($sting)
精彩评论