I have used a function for formatting in sentence case. My PHP script function is
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 . ' ';
}
$new_string = preg_replace( "/\bi\b/", "I", $new_string );
//$new_string = preg_replace("/\bi\'\b/", "I'", $new_string);
$new_string = clean_spaces( $new_string );
$new_string = m_r_e_s( $new_string );
return trim( $new_string );
}
Though its going well and converting whole string in sentence case. But I wish it would skip characters in single quote. Like my string HeLLO world! HOw aRE You. is converting to Hello world! How are you?, but I want to skip the content in the single quotes. Like I wish to skip words in the single quotes. 'HELLO' World and convert words in single quotes to uppercase, otherwise string should remain in sentence case.
You can add another simple regex callback to uppercase words in single quotes. (This is what I understood you want to do.)
If you want this to work for more than one word per quote, use
[\w\s]+in place of\w+. However that would make it more likely to fail for phrases likeisn'twithin the text.