Write a PHP program to reverse the string

Description: Write a PHP program to reverse a string.

Rules and hints:

  • You can use any string related built-in function.
  • Use only one variable.

PHP program to reverse a string

<?php
$str = "Tutorials Class";

echo strrev($str);
?>

Output:

Tutorials Class - Output Window

ssalC slairotuT

How it works

  • strrev() reverses the order of all characters, including the space.

Try this too

  • Check if a word is a palindrome (same when reversed), like “madam”.
  • Reverse the order of the words, and not the letters.

Learn more about the similar topics:
Tutorials
PHP String Handling
Exercises & Assignments
Write a PHP program to reverse the string
Write a PHP program to find the length of the string
Write a PHP program to count the words in the string
Write a PHP program to convert a string into uppercase
PHP Array to String Conversion (favourite colours chosen by user)
Interview Questions & Answers
No Content Found.