This PHP function accepts a string of text that contains one or more sentences, each ending in one of the following ., !, or ? returning properly capitalize text. It is extremely handy when you have a lot of text that is either all lowercase or all uppercase that needs normalizing.function ucsentence($string)
{
if(strlen($string) < 3)
return $string;
$string = strtolower($string);
foreach(array('.', '?', '!') AS $punct)
{
$string = explode($punct, $string);
$count = count ($string);
for($i = 0; $i < $count; $i++)
{
$string[$i] = ucfirst (trim ($string[$i]));
if($i > 0)
{
if((ord($string[$i]{0}) < 48) || (ord($string[$i]{0}) > 57))
$string[$i] = ' '.$string[$i];
}
}
$string = implode($punct, $string);
}
return $string;
}
USAGE:
$paragraph = "THIS IS ANNOYING TEXT. someone doesn't know how to punctuate.";
print ussentence($paragraph);
This function is an enhanced version of one found in the ucwords() section of the PHP documentation comments, extended to test for multiple punctuation types.

