PHP 8.1.0 Beta 1 available for testing

strrev

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

strrevReverte uma string

Descrição

strrev(string $string): string

Retorna a string revertida.

Parâmetros

string

A string a ser revertida.

Valor Retornado

Retorna a string revertida.

Exemplos

Exemplo #1 Revertendo uma string strrev()

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

add a note add a note

User Contributed Notes 4 notes

up
10
tianyiw at vip dot qq dot com
3 years ago
This function support utf-8 encoding, Human Language and Character Encoding Support:

<?php
function mb_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❤☆"
?>
up
-2
info at ensostudio dot ru
10 months 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
*/
function mb_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)
up
-2
manoj904378 at gmail dot com
8 months ago
Inside of String Reverse  strrev()
--------------------------   -------
<?php
$string
= 'This is manoj';
$n =strlen("$string");
For(
$i=1;$i<=$n;$i++)
{
   
$val= $string[-$i];
   echo
$val;
}
?>
up
-32
arturklesun at gmail dot com
3 years ago
Be careful, it does not work with unicode strings.

<?php
php
> $str = '1¥';
php > print($str);

php
> print(strrev($str));
��1
?>
To Top