4 popular PHP function for string case conversion

4 popular PHP function for string case conversion

Working with string become a daily routine for PHP developers. Lot of cool PHP function are available now for altering strings. From them 4 most popular and useful PHP string functions are strtolower(), strtoupper(), ucwords() and ucfirst(). Today we are going to discuss about these 4 string function and know how to use them in PHP. Let’s go-

1. strtolower():

The strtolower() function lowercases all the characters in a string.

// define string
$string = "FREE WEB DEVELOPMENT TUTORIALS BLOG FOR WEB DEVELOPER AND DESIGNER";
// lowercase entire string
$output = strtolower($string);
echo $output;
// result: "free web development tutorials blog for web developer and designer"

2. strtoupper():

The strtoupper() function uppercases all the characters in a string.

// define string
$string = "free web development tutorials blog for web developer and designer";
// uppercase entire string
$output = strtoupper($string);
echo $output;
// result: "FREE WEB DEVELOPMENT TUTORIALS BLOG FOR WEB DEVELOPER AND DESIGNER"

3. ucwords():

The ucwords() function, that capitalizes the first character of every word in the string. It’s very useful for page titles.

// define string
$string = "free web development tutorials blog for web developer and designer";
// uppercase first character of every word of string
$output = ucwords($string);
echo $output;
// result: "Free Web Development Tutorials Blog For Web Developer And Designer"

Live Demo

4. ucfirst():

The ucfirst() function works cool for more precise control on string. The ucfirst() function that capitalizes the first character of a string.

// define string
$string = "free web development tutorials blog for web developer and designer";
// uppercase first character of string

$output = ucfirst($string);
echo $output;
// result: "Free web development tutorials blog for web developer and designer"

 

Enjoy!

Share It

Related Posts