Php string flip method _ PHP Tutorial

Source: Internet
Author: User
Php implements string flip. Php character string flip method this article mainly introduces php character string flip method, which involves php character string operation techniques and has some reference value, A friend in need can refer to php to implement string flip.

This article mainly introduces the php string flip method, which involves php string operation skills and has some reference value. For more information, see

This example describes how to implement string flip in php. Share it with you for your reference. The specific implementation method is as follows:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

Header ("content-type: text/html; charset = utf-8 ");

/**

This function is used to reverse a Chinese string.

Mb_strlen () gets the length of characters

Mb_substr () gets a single element of a character.

Krsort () sorts arrays by key value in reverse order

Implode () concatenates an array into a string

Explode () uses strings to separate strings

*/

Function str_rev_gb ($ str ){

// Determine whether the input is a UTF-8 character. otherwise, exit.

If (! Is_string ($ str) |! Mb_check_encoding ($ str, 'utf-8 ')){

Exit ("The input type is not a UTF-8 string ");

}

$ Array = array ();

// Save the string to an array

$ L = mb_strlen ($ str, 'utf-8 ');

For ($ I = 0; $ I <$ l; $ I ++ ){

$ Array [] = mb_substr ($ str, $ I, 1, 'utf-8 ');

}

// Reverse the string

Krsort ($ array );

// Concatenate a string

$ String = implode ($ array );

Return $ string;

}

$ Str1 = "Englist ";

$ Str2 = "English China ";

$ Str3 = "Eng central lish country ";

$ Str4 = "People's Republic of China ";

Echo $ str1. "->". str_rev_gb ($ str1 )."
";

Echo $ str2. "->". str_rev_gb ($ str2 )."
";

Echo $ str3. "->". str_rev_gb ($ str3 )."
";

Echo $ str4. "->". str_rev_gb ($ str4 )."
";

I hope this article will help you with php programming.

This article describes how to implement string flip in php. it involves php string operation skills and has some reference value. if you need it, you can refer to it...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.