note 9573 added to String functions

From: Date: Mon, 13 Nov 2000 03:25:54 +0000
Subject: note 9573 added to String functions
Groups: php.notes 
Request: Send a blank email to php-notes+get-7622@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-- http://www.php.net/manual/ref.strings.php

« previous php.notes (#7622) next »