• View our reviews on Hot Scripts
  • JS Tutorial

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).

function sentence_case($string) 
    //find sentence
    $sentences = preg_split('/([.?!]+)/', $string, -1, 
    $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

blog comments powered by Disqus