note 9573 deleted from ref.strings by sander
| From: | sander@php.net | Date: | Sun, 07 Apr 2002 13:37:48 +0000 |
| Subject: | note 9573 deleted from ref.strings by sander | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-28919@lists.php.net to get a copy of this message | ||
Here is a 'ucsentence' function. It first makes all chars lower case then makes the first
letter of each sentence capitol. Sentences have to be spaced with a '.'. It will get rid
of annoying messages in all caps and put them in correct sentence form. It will allow acronyms in
the format A.B.C. but will not allow ABC, can't figure out a work around.
function ucsentence($paragraph) {
//make sentences from $paragraph
$sentences=explode(".",trim($paragraph));
FOR ($i=0;$i<count($sentences);$i++) {
$sentences[$i]=trim($sentences[$i]);
//add sentence to new paragraph if it has a lenght greater than 0
$new_paragraph.=(strlen($sentences[$i])>0) ?
ucfirst(strtolower($sentences[$i]))."." : "";
//add a space to the end of sentence if there is a next sentence
//if sentence is only 1 char long, like a A.C.R.O.N.Y.M. do not add space
$new_paragraph.=((strlen($sentences[$i+1])>0 && strlen($sentences[$i])>1) ||
strlen($sentences[$i+1])>1) ? " " : "";
}
return $new_paragraph;
} //--end ucsentence--