How to reverses a given string using PHP.

<?php
function reverseString($str) {
    return strrev($str);
}

$inputString = "Hello, World!";
$reversedString = reverseString($inputString);

echo "Original String: $inputString<br>";
echo "Reversed String: $reversedString";
?>
  • The script defines a function reverseString that uses the strrev function to reverse a given string.
  • The function takes a string as input and returns its reversed version.
  • The script then calls the function with a sample string ($inputString) and prints the original and reversed strings.

Post your Answer