I'm wondering if it is possible to change just the first letter of every sentence in a paragraph to uppercase. I was thinking to do a search of a period with a space and then automatically change the first character to an uppercase. Is this possible?

Thanks in advance,
Owen The Samoan

    Since there is no "string to proper" function, which would be nice, try this:

    $string = strtolower($string);
    $string = substr_replace($string, strtoupper(substr($string, 0, 1)), 0, 1);
    

      The problem here is that I am trying to capitalize the first letter of every sentence in a paragraph that starts with a lower case letter. This can appear anywhere in the paragraph and more than once. I am trying to do this by matching patterns such as the period at the end of a sentence, followed by one to three blank spaces and then a lower case letter. I have tried ereg, preg_replace and str_place but the period and the blank spaces are giving me problems.

        you might be able to create your own function by using the following two:

        strpos() - returns the numeric position of a character
        ucfirst() - returns a the first character of a string capitalized

        use the first to locate the dots, and the second to capitalize the word after the dots found

          You could try something along the lines of:

          $text = ucfirst($text);
          $text = preg_replace_callback('/[.!?].*?\w/',
                                        create_function('$matches', 'return strtoupper($matches[0]);'),
                                        $text);

            Works perfectly! Thank you to everyone for the help! I would never have thought of creating my own function using preg_replace_callback

              You could also shorten it to one line:

              $text = preg_replace('/([\.!\?]\s+|\A)(\w)/e', '"$1" . strtoupper("$2")', $text);
                Write a Reply...