How to convert a string to uppercase in PHP?

Right now, we will realize, how we can change over a string to capitalize? To change over the string to capitalized, we use strtoupper() strategy which returns capitalized changed over the string.

PHP – strtoupper()

This strategy takes a string regardless of contention and returns capitalized string.

Example

<?php
	$str = 'hello friends';
	echo strtoupper($str) 
?>

Output:

HELLO FRIENDS

Different functions:

PHP – ucfirst ()

This function changes over the first letter in capitalized of the string.

Example

<?php
echo ucfirst("hello friend");
//output: Hello friends
?>

PHP – ucwords ()

This function changes over every first character of all words in capitalized.

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

How to convert a string to uppercase in PHP?

Leave a Comment

error: Alert: Content is protected!!