html PHP: strrev - Manual update pague now
PHP 8.5.2 Released!

strrev

(PHP 4, PHP 5, PHP 7, PHP 8)

strrev Reverse a string

Description

strrev ( string $string ): string

Returns string , reversed.

Parameters

string

The string to be reversed.

Return Values

Returns the reversed string.

Examples

Example #1 Reversing a string with strrev()

<?php
echo strrev ( "Hello world!" ); // outputs "!dlrow olleH"
?>

add a note

User Contributed Notes 2 notes

info at ensostudio dot ru
5 years ago
<?php
/**
 * Reverse a miltibyte string.
 *
 * @param string $string The string to be reversed.
 * @param string|null $encoding The character encoding. If it is omitted, the internal character encoding value
 *     will be used.
 * @return string The reversed string
 */functionmb_strrev(string $string, string $encoding= null): string{
    $chars= mb_str_split($string, 1, $encoding?: mb_internal_encoding());
    return implode('', array_reverse($chars));
}?>
It's faster and flexible than tianyiw function (comment #122953)
tianyiw at vip dot qq dot com
7 years ago
This function support utf-8 encoding, Human Languague and Character Encoding Support:<?php
functionmb_strrev($str){$r= '';
    for ($i= mb_strlen($str); $i>=0; $i--) {
        $r.=mb_substr($str, $i, 1);
    }
    return$r;
}

echo mb_strrev("☆❤world"); // echo "dlrow❤☆"?>
To Top