PHP strtoupper Function | Make a String Uppercase

PHP strtoupper converts a PHP string to uppercase characters. In this article, we will discuss the PHP strtoupper Function. Also, we will discuss a few examples of using it.

Also, you can convert a string to lowercase characters using PHP strtolower Function.

Syntax

strtoupper ($string)

Parameters

The strtoupper function expects only one parameter. Pass the string you need to convert to uppercase as the parameter.

Return Value

The function returns a string after converting all alphabetical characters to uppercase.

PHP strtoupper Function | String to Uppercase

Examples

Let’s consider a couple of examples of using the function.

Example 1: Simple String

You can pass an alphabetical string to the function and convert it to uppercase.

<?php

	$string = 'This is a mixed STRING 123';
	$uppercase = strtoupper($string);

	echo $uppercase;
	/* THIS IS A MIXED STRING 123 */

?>

Example 2: Array of Strings

You can use the PHP array_map Function to directly convert all the strings in an array to uppercase by passing strtoupper as the callback function.

<?php

	$arrayOfStrings = array(
		'String 1',
		'string 2 is lower',
		'another string'
	);

	$upperCaseArray = array_map('strtoupper', $arrayOfStrings);
	print_r($upperCaseArray);
	/*
	Array
	(
	    [0] => STRING 1
	    [1] => STRING 2 IS LOWER
	    [2] => ANOTHER STRING
	)
	*/

?>

Conclusion

We discussed the PHP strtoupper in this article. You can read more about it on the Official PHP Documentation. Also, you can read about more String Functions on Concatly.

Spread the Knowledge

Leave a Reply

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