Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

strrev

Reverses a string.

Syntax

strrev(string $string): string

Parameters

ParameterTypeDescription
$stringstringThe source string.

Return value

stringThe string written backwards.

Examples

Reversing a string:

<?php
 
echo strrev('hello');

Output:

olleh

Checking for a palindrome:

<?php
 
$word = 'level';
 
var_dump($word === strrev($word));

Output:

bool(true)

Notes

The function reverses bytes and corrupts non-ASCII text. For that use implode('', array_reverse(mb_str_split($text))).

See also

  • mb_str_split — Splits a string into characters for any alphabet.
  • array_reverse — Returns an array with its elements in reverse order.

Related recipes

In the tutorial

  • Strings — Working with strings in PHP — quotes, concatenation, length, searching, replacing and multibyte functions.

Thanks for reading!

Donate to the site — we work hard for you.