We have learned about some basic string manipulation functions available in PHP in the article PHP | String . In this article, we will learn about few string functions that are used to change cases of characters of strings in PHP. Below are some most commonly used case manipulation functions for strings in PHP:
strtoupper() function in PHP
This function takes a string as argument and returns the string with all characters in Upper Case.
Syntax:
strtoupper($string)
Program to illustrate the use of strtoupper() function:
<?php# PHP code to convert to Upper Casefunction toUpper($string){ return(strtoupper($string));} // Driver Code$string="GeeksforGeeks"; echo (toUpper($string));?> |
Output:
GEEKSFORGEEKS
strtolower() function in PHP
This function takes a string as argument ans returns the string with all of the characters in Lower Case.
Syntax:
strtolower($string)
Program to illustrate the use of strtolower() function:
<?php# PHP code to convert to Lower Casefunction toLower($string){ return(strtolower($string));} // Driver Code$string="GeeksforGeeks"; echo (toLower($string));?> |
Output:
geeksforgeeks
ucfirst() function in PHP
This function takes a string as argument and returns the string with the first character in Upper Case and all other cases of the characters remains unchanged.
Syntax:
ucfirst($string)
Program to illustrate the use of ucfirst() function:
<?php# PHP code to convert the first letter to Upper Casefunction firstUpper($string){ return(ucfirst($string));} // Driver Code$string="welcome to GeeksforGeeks"; echo (firstUpper($string));?> |
Output:
Welcome to GeeksforGeeks
lcfirst() function in PHP
This function takes a string as argument and returns the string with the first character in Lower Case and all other characters remains unchanged.
Syntax:
lcfirst($string)
Program to illustrate the use of lcfirst() function:
<?php# PHP code to convert the first letter to Lower Casefunction firstLower($string){ return(lcfirst($string));} // Driver Code$string="WELCOME to GeeksforGeeks"; echo (firstLower($string));?> |
Output:
wELCOME to GeeksforGeeks
ucwords() function in PHP
This function takes a string as argument and returns the string with the first character of every word in Upper Case and all other characters remains unchanged.
Syntax:
ucwords($string)
Program to illustrate the use of ucwords() function:
<?php# PHP code to convert the first letter # of each word to Upper Casefunction firstUpper($string){ return(ucwords($string));} // Driver Code$string="welcome to GeeksforGeeks"; echo (firstUpper($string));?> |
Output:
Welcome To GeeksforGeeks
strlen() function in PHP
This function takes a string as argument and returns and integer value representing the length of string. It calculates the length of the string including all the whitespaces and special characters.
Syntax:
strlen($string)
Program to illustrate the use of strlen() function:
<?php# PHP code to get the length of any stringfunction Length($string){ return(strlen($string));} // Driver Code$string="welcome to GeeksforGeeks"; echo (Length($string));?> |
Output:
24
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.


