Convert String Uppercase to Lowercase & Lowercase to Uppercase PHP

In this tutorial, we will show you how to convert a string to uppercase and convert a string to lowercase.

PHP String to Uppercase to Lowercase & Lowercase to Uppercase

Here are some ways:

  • 1. Convert string to lowercase
  • 2. Convert string to uppercase
  • 3. PHP uppercase first letter of each word

1. Convert string to lowercase

You can use the php function strtolower() for convert string to lowercase.

PHP strtolower() Function

strtolower() is a built-in PHP function used to convert string to lowercase.

Syntax of this function is:
 strtolower( string );
Example for converting string to lowercase:

Let’s take an example, in this example, we have a one-string and we will use the strtolower() function to convert string to lowercase.

<?php

// original string
$str = "Hello Developers, Have Good Day!";

// convert string to lowercase
$res = strtolower($str);

echo $res;

?> 

The output of the above code is:- ” hello developers, have good day! “

2. Convert string to uppercase

You can use the PHP inbuilt function strtoupper() to convert string to uppercase.

PHP strtoupper() Function

strtoupper() is an inbuilt PHP function used to convert string to strtoupper.

Note:- This function accepts only one parameter as a string.

Syntax of this function is:
 strtoupper( string );
Example for convert string to uppercase

Let’s take an example, in this example, we have a one-string and we will use the strtoupper() function to convert string to uppercase.

<?php

// original string
$str = "hello developers, have good day!";

// convert string to uppercase
$res = strtoupper($str);

echo $res;

?> 

The output of the above code is:- “HELLO DEVELOPERS, HAVE GOOD DAY!”

3. PHP uppercase first letter of each word

You can use the PHP inbuilt function ucwords() for convert uppercase first letter of each word.

PHP ucwords() Function

ucwords() is an inbuilt PHP function, which is used to convert the first letter of each word in a string to uppercase.

Syntax of this function is:
ucwords(string, delimiters);
Example for php uppercase first letter of each word

Let’s take an example, we have a one-string and we will use the ucwords() function to uppercase the first letter of each word.

<?php

// original string
$str = "hello developers, have good day!";

// convert string to uppercase
$res = ucwords($str);

echo $res;

?> 

The output of the above code is: ” Hello Developers, Have Good Day! “

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *