I got this function from php.net for convert uppercase become lowercase in sentence case.
function sentence_case($string) {
$sentences = preg_split('/([.?!]+)/', $string, -1, PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE);
$new_string = '';
foreach ($sentences as $key => $sentence) {
$new_string .= ($key & 1) == 0
? ucfirst(strtolower(trim($sentence)))
: $sentence . ' ';
}
return trim($new_string);
}
If the sentence is not in the paragraph, all works well. But if the sentence is in the paragraph, the first letter in opening paragraph (<p>
) or break (<br>
) tag HTML become lowercase.
This is the sample:
Before:
<p>Lorem IPSUM is simply dummy text. LOREM ipsum is simply dummy text! wHAt is LOREM IPSUM? Hello lorem ipSUM!</p>
Output:
<p>lorem ipsum is simply dummy text. Lorem ipsum is simply dummy text! What is lorem ipsum? Hello lorem ipsum!</p>
Can someone help me to make the first letter in the paragraph become capital letter?