0

Changing Case (Uppercase to lowercase or inverse) using php

PHP provides functionality for changing the case of a string to all uppercase, all lowercase, or the first letter of a word to uppercase. The commands are strtoupper, strtolower, and ucwords, respectively.

Using the word case functions

$username="John Doe";
echo("$username in upper case is ".strtoupper($username).".
");
echo("$username in lower case is ".strtolower($username).".
");
echo("$username in first letter upper case is ".ucwords($username).".
");
?>

The above code returns:

John Doe in upper case is JOHN DOE.
John Doe in lower case is john doe.
John Doe in first letter upper case is John Doe.

Filed in: PHP Functions

Recent Posts

Bookmark and Promote!

© 2012 Sumit Bansal. All rights reserved. XHTML / CSS Valid.