HOW TO: PHP Capital Letters in every word??

Posted on 2006-11-05
Last Modified: 2012-05-05
Hi Experts

I have a string I want to convert every word in the string to capital starting letter.

'PLEASE HELP ME' or 'please help me'
'Please Help Me'

Thanks for your help

Question by:nikdonovanau
  • 2
LVL 19

Accepted Solution

VoteyDisciple earned 500 total points
ID: 17878875
$var = 'PLEASE HELP ME';
$var = ucwords(strtolower($var));
LVL 19

Expert Comment

ID: 17878878
The classic mistake is to write just ucwords($var) but that's incorrect.  ucwords() will only make the beginning letter of each word uppercase; it will not make anything else lowercase.  That's easy to work around, though: just convert the entire string to lowercase first, THEN convert all the beginnings of words to uppercase.

Author Comment

ID: 17878892
Perfect - Thanks very much for that

Have a good one :)

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity default error log 1 40
Change background color in td if any value is 1 9 23
php56-php-mcrypt for rhel7 php56 1 50
Help with PHP 13 27
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

856 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