Q:

How to convert a string to uppercase in PHP?

belongs to collection: PHP String Programs

0

How to convert a string to uppercase in PHP?

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

PHP - strtoupper()

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

Example

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

Output

HELLO FRIENDS

Other 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 example to convert into uppercase

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

PHP program to convert string to uppercase without... >>
<< Check if string contains a particular character in...