pTutorial

New way to learn PHP Example

PHP Change Case Example

Change case

PHP provides built-in functions to convert a string, lower to upper caseand upper case to lower case or capital case. In this section we will learn how to use this function.

Change lower case to upper case using strtoupper() function

<?php

$a = "A variable is declared within a block procedure";

print(strtoupper($a)."
"); //using variable $b="A variable is declared within a block procedure"; $ans=strtoupper($b);//using variable echo($ans."
"); print(strtoupper("A variable is declared within a block procedure
")); //without variables ?>

Explanation

First, create a variable $a and store any string which you want to convert to upper case. After that, pass this variable as an argument in the strtoupper function and print. You can do this thing by using variable, without variable and in a single statement as above.

ucfirst function example

<?php

$a = "A variable is declared within a block procedure";

print(ucfirst($a)."
"); //using variable $b="A variable is declared within a block procedure"; $ans=ucfirst($b);//using variable echo($ans."
"); print(ucfirst("upper case
")); //without variables ?>

Explanation

Ucfirst function is used to convert the first character of the sentence into upper case letters. It takes one argument as a string and returns the first character of the sentence in upper case.

Example ucword function

<?php

$a = "A variable is declared within a block procedure";

print(ucwords($a)."
"); //using variable $b="A variable is declared within a block procedure"; $ans=ucwords($b);//using variable echo($ans."
"); print(ucwords("A variable is declared within a block procedure
")); //without variables ?>

Explanation

ucword function is used to convert the first character of the all word of a given sentence into the capital.


QUOTES OF THE DAY

Crafty men condemn studies, simple men admire them, and wise use them.

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER