Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Make Sentence Case (See related posts)

// Run text through this to make it sentence case...
// "the pretty pink sandwich" becomes:
// "The pretty pink sandwich"


function sentence_case($s) {
   $str = strtolower($s);
   $cap = true;
   for($x = 0; $x < strlen($str); $x++){
       $letter = substr($str, $x, 1);
       if($letter == "." || $letter == "!" || $letter == "?"){
           $cap = true;
       }elseif($letter != " " && $cap == true){
           $letter = strtoupper($letter);
           $cap = false;
       }
       $ret .= $letter;
   }
   return $ret;
}


You need to create an account or log in to post comments to this site.


Related Posts