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" ?>

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>