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.

1. strtolower():

The strtolower() function lowercase 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 uppercase 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"

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!

Total 0 Votes
0

Tell us how can we improve this post?

+ = Verify Human or Spambot ?

Leave a Comment

Back To Top
Cool Ajax - Web Development Tutorial Blog
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.