PHP 8 reference · String Functions

PHP strrev() Function

Reverse a string byte by byte. Fine for ASCII, but it breaks multibyte characters such as é.

PHP 8 Since 4.0

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

strrev(string $string): string

Parameters

ParameterDescription
string The input string.

Return value

The reversed string.

Examples

Reverse textTry it yourself
<?php
echo strrev("camel"), "\n";
echo strrev("12345"), "\n";

Output

lemac
54321
Palindrome checkTry it yourself
<?php
$word = "racecar";
echo $word === strrev($word) ? "palindrome" : "not a palindrome", "\n";

Output

palindrome

Common mistakes

  • For UTF-8 text, reverse the characters instead: implode("", array_reverse(mb_str_split($text))).

Version history

VersionChange
PHP 4.0Added

Was this page helpful?