PHP- capitalize all words in a string

Posted on 2007-10-05
Last Modified: 2008-01-09
Hello!  I've been sitting here Googling this, but getting frustrated because I can't find the PHP code for what I want to do specifically:

$string = I want to CAPITALIZE all WOrds IN a sTRING

How can I make the above string read:

$string = I Want To Capitalize All Words In A Strong

Thank you in advance!!!
Question by:mcgeorge40
    LVL 24

    Accepted Solution

    $string = "I want to CAPITALIZE all WOrds IN a sTRING";

    $result = ucwords(strtolower($string));

    Author Comment

    Thanks.  I actually had that code...  And I realized I had a typo.  Darn!  Thank you for the quick response.
    LVL 24

    Expert Comment

    With PHP's schizophrenic function-naming conventions, typos are often easy to come by, and difficult to spot. I'm glad it is working for you now!

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
    Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now