Use PHP to Capitalise Your Text

If you want to make sure your text is nicely formatted there are a couple of tricks using PHP that can help you.

Changing the case of your words is one useful feature, that can be achieved with the functions in the following example.

echo strtoupper('abc'); # outputs: ABC
echo strtolower('ABC'); # outputs: abc
echo ucfirst('frogs eat dogs.'); # outputs: Frogs eat dogs.
echo ucwords('frogs eat dogs.'); # outputs: Frogs Eat Dogs.

One thing to watch out for is if your text is uppercase (or mostly uppercase) and you want to use ucfirst() or ucwords() to capitalise the first letters - you won’t get the desired effect. Ensure you use strtolower() first, as follows:

echo ucfirst ('FROGS EAT DOGS ON LOGS.'); # outputs: FROGS EAT DOGS ON LOGS.
echo ucfirst (strtolower('FROGS EAT DOGS ON LOGS.')); # outputs: Frogs eat dogs on logs.

Looking after the presentation of your text like this can make a huge difference to the perceived quality of your site. If you allow users to enter their own text at all, then it is a great idea to capitalise it using these php functions.

Are you a Developer, Designer or Copy Writer? Or Looking For One?

Click here to see 100s of jobs updated every day that you can complete to earn good money. Also find that programmer, designer or copy writer you have been looking for - advertise and get the best guy for your job - click here to find out more

Leave a Reply

Make $100,000/Month - Every Month!

It Works! We Make Our Customers Millionaires! Act now and get $600 bonus and a Free Money Making Website! - click to get started