PHP Tutorial

PHP Examples

PHP Practice

How to convert a string to uppercase in PHP?

Learn, how can we convert a string to uppercase? To convert string to uppercase, we use strtoupper() method which returns uppercase converted string. By IncludeHelp Last updated : December 19, 2023


To understand this example, you should have the basic knowledge of the following PHP topics:

PHP - Converting a string to uppercase

To convert a given string to uppercase in PHP, we use strtoupper() method.

strtoupper() Function

This method takes a string in any case as an argument and returns uppercase string.



PHP code to convert string into uppercase

// Declaring a variable and assigning
// string in it
$str = "hello friends";

// Converting to uppercase, and printing it
echo strtoupper($str);



Other similar functions

PHP - ucfirst ()

This function converts first letter in uppercase of the string.


echo ucfirst("hello friend");
//output: Hello friends

PHP - ucwords ()

This function converts each first character of all words in uppercase.


echo ucwords("how are you");
//Output: How Are You?

Complete code (HTML with PHP)

		<title> PHP code to get textbox value and print it in Uppercase </title>
		<form action="">
			<input type="text" id="str" type="text" name="str" maxlength="10" size="26">

			<input type="submit" name="submit" formmethod="POST">

				$str = strtoupper($_POST['str']);
				echo "convert to upper case";
				echo $str;	


PHP example to convert into uppercase

PHP String Programs »

Comments and Discussions!

Load comments ↻

Copyright © 2024 All rights reserved.