PHP | String Functions - GeeksforGeeks

09 Mar, 2018
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
C-String-Question
Functions
PHP-function
PHP
Web Technologies
Functions
PHP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
How to Insert Form Data into Database using PHP ?
How to convert array to string in PHP ?
How to Upload Image into Database and Display it using PHP ?
How to check whether an array is empty using PHP?
How to receive JSON POST with PHP ?
Top 10 Front End Developer Skills That You Need in 2022
Installation of Node.js on Linux
Top 10 Projects For Beginners To Practice HTML and CSS Skills
How to fetch data from an API in ReactJS ?
How to insert spaces/tabs in text using HTML/CSS?