Home > Backend Development > PHP Tutorial > A simple method to flip multi-byte strings in PHP_PHP Tutorial

A simple method to flip multi-byte strings in PHP_PHP Tutorial

WBOY
Release: 2016-07-13 09:58:41
Original
996 people have browsed it

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

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:...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template