Recommended:

  • phpclasses.org
  • jsclasses.org
  • jsmag.com
  • siteapps.com
  • View our reviews on Hot Scripts
  • JS Tutorial
  • scripts.com
  • securesignup.com




Recent Comments

Powered by Disqus




Back to articles

Make first letter of every sentence uppercase

This function takes text as a parameter and makes first letter of every sentence to the uppercase. You can modify it, to make all string lowercase before making first letter uppercase (if you have whole text in CAPS for example).

<?php
function sentence_case($string) 
{ 
    //find sentence
    $sentences = preg_split('/([.?!]+)/', $string, -1, 
                            PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE); 
    $new_string = ''; 
    foreach ($sentences as $key => $sentence) 
    { 
        $new_string .= ($key & 1) == 0? 
        //you may add strtolower function before ucfirst to make everything lower case
        ucfirst(trim($sentence)) : 
        $sentence.' '; 
    } 
    return trim($new_string); 
}
?>

You may also be interested in:

Powered by BlogAlike.com

blog comments powered by Disqus