Today I come with some useful PHP functions which are very useful to understand case functions of PHP.
Case functions change the string from lowercase to uppercase and vice versa and those functions are strtolower,strtoupper, ucfirst and ucwords. strtolower function decapitalizes entire strings whereas strtoupper function capitalizes entire strings. Other case functions operate only on first letters of words which are.ucwords and ucfirst.
Lets checkout functions one by one:
The strtolower() function returns an all lowercase string. It doesn’t matter if the original is all uppercase or mixed,just returned string will be in lowercase.
string strtolower (string str)
It returns the string with all alphabetic characters converted to lowercase.
Lets see example:
$original = "PHP is recursive acronym of Hypertext Preprocessor"; $lower = strtolower($original); echo $lower;
PHP is recursive acronym of hypertext preprocessor
strtolower() is extremely easy to use.you can decapitalize e-mail addresses contain capital letters.
The strtoupper() function returns an all uppercase string, in spite of whether the original was all lowercase or mixed,It will capitalize the string.
$original ="PHP is recursive acronym of Hypertext Preprocessor"; $upper = strtoupper($original); echo $upper;
PHP IS RECURSIVE ACRONYM OF HYPERTEXT PREPROCESSOR
The ucfirst() function which capitalizes only the first character of a string.
$original ="php is recursive acronym of Hypertext Preprocessor"; $ucfirst=ucfirst($original); echo $ucfirst;
Php is recursive acronym of Hypertext Preprocessor
The ucwords() function capitalizes the first character of each word in a string:
$original ="php is recursive acronym of Hypertext Preprocessor"; $ucwords=ucwords($original); echo $ucwords;
Php Is Recursive Acronym Of Hypertext Preprocessor
Neither ucwords() nor ucfirst() converts anything into lowercase. Each makes only the
appropriate significant characters into uppercase. If there are inappropriate capital characters in the middle of words, they will not be converted.
Do let me know case functions of PHP is useful to you. I would love to hear your opinions & experiences in the comments section below.
If you enjoyed reading this article, do share it your friends who are working in PHP.