PHP strrev() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
String

Definition

In PHP, strrev() reverses a string character by character.

It takes one argument and returns the reversed text. It is a common helper for palindrome checks.

Syntax

Call strrev() with the values you need. Start with this line.

PHP
$reversed = strrev("Hello");
CallWhat it does
strrev("Hello")Returns "olleH".
strrev("level") === "level"True because "level" is a palindrome.
strrev("one two")Returns "owt eno" (the whole string is reversed).

strrev() works on bytes, so it can break multi-byte characters such as emojis or accented letters in UTF-8. For those, use mb_str_split() with array_reverse().

Library declarations
PHP
strrev(string $string): string

Parameters

ParameterDescription
stringRequired. The string to reverse.

Return Value

Return ValueDescription
stringThe reversed string.

PHP Examples

Example 1 — Reverse a Word

The simplest use of strrev().

PHP
<?php
$word = "Hello";

echo strrev($word), PHP_EOL;

How It Works

  1. Store a word in a variable.
  2. Pass it to strrev.
  3. PHP reads the characters from the end to the start.
  4. The reversed word is printed.

Example 2 — Check for a Palindrome

A palindrome reads the same forwards and backwards.

PHP
<?php
$word = "level";

if (strrev($word) === $word) {
    echo $word, " is a palindrome", PHP_EOL;
} else {
    echo $word, " is not a palindrome", PHP_EOL;
}

How It Works

  1. Store the word to test.
  2. Reverse it with strrev.
  3. Compare the reversed text with the original using ===.
  4. If both are equal, the word is a palindrome.

Example 3 — Reverse Characters vs Reverse Words

strrev() flips letters, not word order. Use explode() for that.

PHP
<?php
$text = "one two three";

echo strrev($text), PHP_EOL;
echo implode(" ", array_reverse(explode(" ", $text))), PHP_EOL;

How It Works

  1. Start with a sentence of three words.
  2. strrev reverses every character, so the words are also mirrored.
  3. To reverse only the order of the words, explode into an array.
  4. Use array_reverse and then implode to join the words back.

Frequently Asked Questions

strrev() returns a string with its characters in reverse order. For example, strrev('abc') returns 'cba'.
Not safely. strrev() reverses bytes, which can break multi-byte characters. For UTF-8, use mb_str_split() and array_reverse().
Compare the string with its reverse: strrev($word) === $word. You may want to lowercase it first with strtolower().
Use implode(' ', array_reverse(explode(' ', $text))). strrev() reverses letters, not words.
No. It returns a new string. The original variable stays the same unless you assign the result back.

Next: strripos()

strripos() finds the position of the last occurrence of a substring in a string, ignoring .

strripos() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful