I am trying to write a function to clean up user input.
I am not trying to make it perfect. I would rather have a few names and acronyms in lowercase than a full par
Here is the code that does as you wanted:
<?php
$str = "paste your code! below. codepad will run it. are you sure?ok";
//first we make everything lowercase, and
//then make the first letter if the entire string capitalized
$str = ucfirst(strtolower($str));
//now capitalize every letter after a . ? and ! followed by space
$str = preg_replace_callback('/[.!?] .*?\w/',
create_function('$matches', 'return strtoupper($matches[0]);'), $str);
//print the result
echo $str . "\n";
?>
OUTPUT: Paste your code! Below. Codepad will run it. Are you sure?ok