note 33152 deleted from function.ucfirst by nlopess
| From: | nlopess@php.net | Date: | Tue, 02 Mar 2004 15:24:23 +0000 |
| Subject: | note 33152 deleted from function.ucfirst by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-66110@lists.php.net to get a copy of this message | ||
Note Submitter: Stephen
----
Couldn't find a good function to fix uppercase paragraphs
(caps lock stuck??) for a message board project ... this works
pretty well. (tested)
echo FixTextCase("SHOUTING TEXT.ONEWORD? NEXT SENTENCE... BLA.");
// produces "Shouting text. Oneword? Next sentence... Bla."
function FixTextCase($text) {
$text = strtolower($text);
$sentences = preg_split("/(\.(\s)?|\?(\s)?)/",$text,
-1,PREG_SPLIT_DELIM_CAPTURE);
foreach($sentences as $x) {
if ((trim($x) == ".") || (trim($x) == "?")) {
$outtext .= trim($x)." ";
} else {
$outtext .= ucfirst(trim($x));
}
}
// fix double mark errors
$outtext = preg_replace("/(\s\.)/",".",$outtext);
$outtext = preg_replace("/(\s\?)/","?",$outtext);
return $outtext;
}
(make sure the preg_split function is all on one line ...)