When a user submit a form, let's say a text area, with caps lock on, there are a few options I know we can do to 'fix' the case, some of them are:
- PHP - ucfirst(mb_strtolower($str));
- CSS - text-transform: lowercase;
And some variations, combining the above methods with some others. That's fine, but that won't fix the capitalisation correctly for most cases.
The goal is not to have "ALL CAPS TEXT", nor "This Is A text", or even worst "all lower case. even paragraphs, etc".
Let's say I have this text:
"HELLO, MY NAME IS JHON. I'M A PROGRAMMER. I work at BBC UK"
It's probably not possible to transform this string correctly as it should be (let me know if I'm wrong):
"Hello, my name is Jhon. I'm a programmer. I work at BBC UK"
I'm fine if this ain't possible in any way. But there's a way to just have some logic, despite all lowercase, or camel case, etc?
Something like:
"Hello, my name is jhon. I'm a programmer. I work at bbc uk"
With all lower cases, but paragraphs first letter, and the first letter after dots, would be all right.
Is there some jquery plugin, some php class, whatever, I'm not aware of, that can do this?
I'm sorry if this question is somehow a duplicate of a thousand other related questions, but all I could find was code that just won't format properly the cases and lots of solutions that won't fit all cases, like: PHP remove all caps
<?php
function ucwordsreplace($matches) {
return ucwords(strtolower($matches[0]));
}
$original = "some UPPERCASE words GO HERE";
$fixed = preg_replace_callback('/\b[A-Z]+\b/', "ucwordsreplace", $original);
echo $fixed; // some Uppercase words Go Here