PHP Reverse String Example

Reverse a string with strrev() and check for palindromes. Edit the code below and press Run to execute it with real PHP in your browser.

Code Editor
Output
Original: Hello
Reversed: olleH
Racecar is a palindrome

How this reverse string example works

strrev() reverses a string byte by byte. That is correct for ASCII text, but it scrambles multibyte UTF-8 characters such as "é". For Unicode text, split into characters first: implode("", array_reverse(preg_split('//u', $s, -1, PREG_SPLIT_NO_EMPTY))).