A simple method for flipping multi-byte strings in PHP
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:
1
2
3
4
5
6
7
8
9
10
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;
}
|
1
2
3
4
5
6
7
8
9
10
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;
}
|
http://www.bkjia.com/PHPjc/977158.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/977158.htmlTechArticleHow to simply implement multi-byte string flipping in PHP. This article describes how to simply implement multi-byte string flipping in PHP. method. Share it with everyone for your reference. The specific implementation method is as follows:...