Created
June 22, 2018 08:22
-
-
Save lovelock/980e1f26a432bae7bf23f0ea56474492 to your computer and use it in GitHub Desktop.
reverse multibyte strings in PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// http://kvz.io/blog/2012/10/09/reverse-a-multibyte-string-in-php/ | |
function mb_strrev ($string, $encoding = null) { | |
if ($encoding === null) { | |
$encoding = mb_detect_encoding($string); | |
} | |
$length = mb_strlen($string, $encoding); | |
$reversed = ''; | |
while ($length-- > 0) { | |
$reversed .= mb_substr($string, $length, 1, $encoding); | |
} | |
return $reversed; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment