Back to Top

How to Define and Call Case functions in PHP

Case functions in PHP

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:

1. strtolower():

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.

Description

string strtolower (string str)

It returns the string with all alphabetic characters converted to lowercase.

Note that ‘alphabetic’ is determined by the current locale settings. This means that when “C” locale default characters such as umlaut-A will not be converted.

Lets see example:

OUTPUT

PHP is recursive acronym of hypertext preprocessor

strtolower() is extremely easy to use.you can decapitalize e-mail addresses contain capital letters.

2. strtoupper()

The strtoupper() function returns an all uppercase string, in spite of whether the original was all lowercase or mixed,It will capitalize the string.

OUTPUT:

PHP IS RECURSIVE ACRONYM OF HYPERTEXT PREPROCESSOR

3. ucfirst()

The ucfirst() function which capitalizes only the first character of a string.

OUTPUT

Php is recursive acronym of Hypertext Preprocessor

4. ucwords()

The ucwords() function capitalizes the first character of each word in a string:

OUTPUT

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular Posts

Buffered Vs Unbuffered Queries in PHP

Posted on 12 years ago

Bhumi

Custom Directives in Angular JS

Posted on 9 years ago

Bhumi