Home >Backend Development >PHP Tutorial >A simple method to flip multi-byte strings in PHP_PHP Tutorial
This article describes an example of a simple method for flipping multi-byte strings in PHP. Share it with everyone for your reference. The specific implementation method is as follows:
4 11 12 |
<🎜>function mb_strev ($string, $encoding = null) {<🎜> <🎜>if ($encoding === null) {<🎜> <🎜>$encoding = mb_detect_encoding($string);<🎜> <🎜>}<🎜> <🎜>$length = mb_strlen($string, $encoding);<🎜> <🎜>$reversed = '';<🎜> <🎜>while($length-- > 0) { $reversed .= mb_substring($string, $length, 1, $encoding); } return $reversed; } |