Write a php script to transform a string all uppercase letters

Last update on August 19 2022 21:50:37 (UTC/GMT +8 hours)

PHP String: Exercise-1 with Solution

Write a PHP script to : -

a) transform a string all uppercase letters.
b) transform a string all lowercase letters.
c) make a string's first character uppercase.
d) make a string's first character of all the words uppercase.

Pictorial Presentation:

Write a php script to transform a string all uppercase letters

Sample Solution:

PHP Code:

<?php
//all uppercase letters
print(strtoupper("the quick brown fox jumps over the lazy dog."))."\n";
//all lowercase letters
print(strtolower("THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG"))."\n";
// make a string's first character uppercase
print(ucfirst("the quick brown fox jumps over the lazy dog."))."\n";
// make a string's first character of all the words uppercase
print(ucwords("the quick brown fox jumps over the lazy dog."))."\n";
?>

Sample Output:

THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.                
the quick brown fox jumps over the lazy dog                 
The quick brown fox jumps over the lazy dog.                
The Quick Brown Fox Jumps Over The Lazy Dog.

Flowchart :

Write a php script to transform a string all uppercase letters

PHP Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: PHP String Exercises Home.
Next: Write a PHP script to split the specific string.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

PHP: Tips of the Day

PHP: How to define an empty object in PHP?

$x = new stdClass();

stdClass is the default PHP object. stdClass has no properties, methods or parent. It does not support magic methods, and implements no interfaces.

When you cast a scalar or array as Object, you get an instance of stdClass. You can use stdClass whenever you need a generic object instance.

Ref : https://bit.ly/2Q96Wvm


  • Exercises: Weekly Top 16 Most Popular Topics
  • SQL Exercises, Practice, Solution - JOINS
  • SQL Exercises, Practice, Solution - SUBQUERIES
  • JavaScript basic - Exercises, Practice, Solution
  • Java Array: Exercises, Practice, Solution
  • C Programming Exercises, Practice, Solution : Conditional Statement
  • HR Database - SORT FILTER: Exercises, Practice, Solution
  • C Programming Exercises, Practice, Solution : String
  • Python Data Types: Dictionary - Exercises, Practice, Solution
  • Python Programming Puzzles - Exercises, Practice, Solution
  • C++ Array: Exercises, Practice, Solution
  • JavaScript conditional statements and loops - Exercises, Practice, Solution
  • C# Sharp Basic Algorithm: Exercises, Practice, Solution
  • Python Lambda - Exercises, Practice, Solution
  • Python Pandas DataFrame: Exercises, Practice, Solution
  • Conversion Tools
  • JavaScript: HTML Form Validation


❮ PHP String Reference

Example

Convert all characters to uppercase:

<?php
echo strtoupper("Hello WORLD!");
?>

Try it Yourself »


Definition and Usage

The strtoupper() function converts a string to uppercase.

Note: This function is binary-safe.

Related functions:

  • strtolower() - converts a string to lowercase
  • lcfirst() - converts the first character of a string to lowercase
  • ucfirst() - converts the first character of a string to uppercase
  • ucwords() - converts the first character of each word in a string to uppercase

Syntax

Parameter Values

ParameterDescription
string Required. Specifies the string to convert

Technical Details

Return Value:Returns the the uppercased string
PHP Version:4+

❮ PHP String Reference


Topic: PHP / MySQLPrev|Next

Answer: Use the PHP strtoupper() function

You can use the PHP strtoupper() function to convert a string to uppercase.

Let's try out the following example to understand how this function basically works:

<?php
$my_str = 'The quick brown fox jumps over the lazy dog.';
echo strtoupper($my_str);
?>


Here are some more FAQ related to this topic:

  • How to convert a string to lowercase in PHP
  • How to convert the first letter of a string to uppercase in PHP
  • How to reverse a string in PHP

How can I uppercase all letters in PHP?

The strtoupper() function converts a string to uppercase. Note: This function is binary-safe. Related functions: strtolower() - converts a string to lowercase.

How do I convert all letters to lowercase in PHP?

The strtolower() function converts a string to lowercase. Note: This function is binary-safe. Related functions: strtoupper() - converts a string to uppercase.

Which of the following function will convert a string to all uppercase?

The toUpperCase() method returns the value of the string converted to uppercase.

What is the use of Strtolower () function give code?

The strtolower() function is used to convert a string into lowercase. This function takes a string as parameter and converts all the uppercase english alphabets present in the string to lowercase. All other numeric characters or special characters in the string remains unchanged.