Php string flip method, php string flip _ PHP Tutorial

Source: Internet
Author: User
Php implements string flip, and php string flip. Php string flip method. php string flip this article describes how php implements string flip. Share it with you for your reference. The specific implementation method is as follows: phphead php implements string flip, php string flip

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

<? Phpheader ("content-type: text/html; charset = utf-8");/** This function is used to reverse the Chinese string mb_strlen () to obtain the length of the character mb_substr () get a single element of the character krsort () sort the array implode () by key value in reverse order and concatenate the array into a string explode () using a string to separate the string */function str_rev_gb ($ str) {// Determine whether the entered character is utf8; 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 中llish"; $ 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.

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

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.