Blinding Light: Free Web Layouts, Anime Transparent PNG, PS Brushes, Coding Tutorials and more!

Blinding Light: Web Layouts, PS Brushes, Coding Tutorials, Transparent PNG

Changing Cases

For those who aren't acquainted with PHP, changing uppercase letters to lowercase and vice versa is not easy. Thankfully, PHP is around to provide functions to do this for you. Without further delays, we'll continue with the lesson...

Step 1: Uppercase

This part will discuss how you can change all the letters to uppercase. Here's the code:

<?php

$Text = "example";
$Text = strtoupper($Text);
echo $Text;

?>

In the code above, we changed Text from example to EXAMPLE. This can be handy if you have a blog and you want the title of your entries to be all uppercase.

Step 2: Lowercase

This part will discuss how you can change all the letters to lowercase. Here's the code:

<?php

$Text = "EXAMPLE";
$Text = strtolower($Text);
echo $Text;

?>

In the code above, we changed Text from EXAMPLE to example. Good for getting rid of those ugly sTiCkY caps.

Step 3: Capitalize 1st Letter

This part will discuss how you can change the first letter of the first word to uppercase. Here's the code:

<?php

$Text = "this is an example";
$Text = ucfirst($Text);
echo $Text;

?>

In the code above, we changed Text from this is an example to This is an example. Best for one-liners.

Step 4: Capitalize 1st Letter Of Each Word

This part will discuss how you can change the first letter of each word to uppercase. Here's the code:

<?php

$Text = "this is an example";
$Text = ucwords($Text);
echo $Text;

?>

In the code above, we changed Text from this is an example to This Is An Example. Usually used for names or titles of articles.

Conclusion

I told you it was easy. Try it out for yourself and see how great PHP is.

If you have any questions or if you want to discuss this tutorial, you may post at Blinding Light MB.

Web site design, scripting and contents © 2003-08 Miko Reznor.
No part of this site may be republished without permission.