Solved

HOW TO: PHP Capital Letters in every word??

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

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

Eg
From
'PLEASE HELP ME' or 'please help me'
to
'Please Help Me'

Thanks for your help

Cheers
Nik
0
Comment
Question by:nikdonovanau
  • 2
3 Comments
 
LVL 19

Accepted Solution

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

Expert Comment

by:VoteyDisciple
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.
0
 
LVL 1

Author Comment

by:nikdonovanau
ID: 17878892
Perfect - Thanks very much for that

Have a good one :)
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

810 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