Home »
PHP »
PHP programs
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.
Submitted by IncludeHelp, on October 17, 2017 [Last updated : March 13, 2023]
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.
Syntax
strtoupper(string)
PHP code to convert string into uppercase
<?php
$str = 'hello friends';
echo strtoupper($str)
?>
Output
HELLO FRIENDS
Other similar functions
PHP - ucfirst ()
This function converts first letter in uppercase of the string.
Example
<?php
echo ucfirst("hello friend");
//output: Hello friends
?>
PHP - ucwords ()
This function converts each first character of all words in uppercase.
Example
<?php
echo ucwords("how are you");
//Output: How Are You?
?>
Complete code (HTML with PHP)
<html>
<head>
<title> PHP code to get textbox value and print it in Uppercase </title>
</head>
<body>
<form action="">
<input type="text" id="str" type="text" name="str" maxlength="10" size="26">
<input type="submit" name="submit" formmethod="POST">
</form>
<?php
if(isset($_POST['submit']))
{
$str = strtoupper($_POST['str']);
echo "convert to upper case";
echo $str;
}
?>
</body>
</html>
Output
PHP String Programs »