Convert an ALL CAPS string to first character capitalized only in PHP

Nothing new to you php gurus, but hope this can help somebody looking for a quick fix – great to filter user inputs in things like addresses, company names, and yes regular ole names. It utilizes PHP’s ucwords() and strtolower():

<?

$userInput1 = “MR. CAPITAL LETTERS”;
$userInput2 = “mrs. lowercase letters”;

ucwords(strtolower($userInput1)); //outputs “Mr. Capital Letters”
ucwords(strtolower($userInput2)); //outputs “Mrs. Lowercase Letters”

?>

Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never shared. Required fields are marked *

*
*
<From the blog>

© 2010 Rainmaker Web Design | 244 Bloomfield Street | Athens, GA 30605 | V: (770) 377-6345 | F: (770) 640-1599