4 string functions to convert string case in PHP | strtoupper() function in php | strtolower() function in php | ucfirst | ucwords function in php

Dear Readers. In this article we will discuss 4 PHP functions to convert case of letter one by one.

  1. strtoupper
  2. strtolower
  3. ucfirst
  4. ucwords

What is string ?

A string is a collection/sequence of characters. String is one of the data types supported by PHP. The string variables can contain alphanumeric characters. Strings are created when; You declare variable and assign string characters to it. example: $str = “This is string variable”;

Note: only text can be converted: number or special symbol can’t effect anything.

PHP strtoupper() Function

strtoupper() takes one string parameter, and returns that string entirely in uppercase:

syntax

strtoupper("This is uppercase test")

Example 1: strtoupper function in php

<?php
$string = "My name is Pradip Mehta";

echo "Origin text is : <b>$string</b>";

echo "<br/><br/> After convernted in uppercase text is :<b>".strtoupper($string)."</b>";

?>
 strtoupper function in php
strtoupper function in php

Also, Read

Example 2: strtoupper function in php

<?php
$string = "My name is Pradip Mehta @1991";

echo "Origin text is : <b>$string</b>";

echo "<br/><br/> After convernted in uppercase text is :<b>".strtoupper($string)."</b>";

?>
strtoupper function in php
strtoupper function in php

PHP strtolower() Function

strtolower() takes one string parameter, and returns that string entirely in lowercase:

syntax

strtolower("This is lowercase test")
<?php
$string = "My name is Pradip Mehta";

echo "Origin text is : <b>$string</b>";

echo "<br/><br/> After convernted in lowercase text is :<b>".strtolower( $string)."</b>";

?>
strtolower() function in php
strtolower() function in php

PHP ucfirst() Function

The ucfirst() function converts the first character of a string to uppercase

syntax

<?php
echo ucfirst("this is ucfirst function in php");
?>
<?php
$string = "this is ucfirst function in php";

echo "Origin text is : <b>$string</b>";

echo "<br/><br/> After convernted :<b>".ucfirst( $string)."</b>";

?>
ucfirst function in php
ucfirst function in php

PHP ucwords() Function

The ucwords() function converts the first character of each word in a string to uppercase.

syntax

<?php
echo ucwords("this is ucfirst function in php");
?>
<?php
$string = "this is ucfirst function in php";

echo "Origin text is : <b>$string</b>";

echo "<br/><br/> After convernted :<b>".ucwords( $string)."</b>";
?>
ucwords function in php
ucwords function in php

Note: If you want to work on with non-Latin UTF-8 text (δρασκελίζει) then you have to use in prefix mb e.g. mb_strtoupper for convert the text into uppercase similarly for other function you can use. for more details click here.

Pradip Mehta

I am a well-organized professional in Drupal Development and PHP web development with strong script handling knowledge or automation process with PHP. I have advanced computer skills and am a proficient multitasker.