Tools
- Sandbox
- Paste Code
- Snippets
- Generators
- Checks
- Convertors
- Home
- php
- Сonverters
- Reverse string in PHP
Reverse string in PHP
Snippet
Share
Do you find this snippet useful? Then share it with your friends or colleagues. This will help us to make our free web tools better.
Reverse string using strrev() function:
<?php
$string = "WTOOLS";
echo "Reverse string of $string is " .strrev ( $string );
Be careful, it does not work with unicode strings.
Reverse string without using strrev() and support utf-8 encoding:
<?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("❤WTOOLS☆");