How does PHP implement string flip?

Source: Internet
Author: User
How does PHP implement string flip? Are there any existing functions ?, Strrev () or $ str = & quot; abcdefg & quot; functionstrrevv ($ str) {$ len = strlen ($ str); $ newstr = ''; for ($ I = $ len; $ I How does PHP implement string flip?
Are there any existing functions?

------ Solution --------------------
Strrev ()
Or
$ Str = "abcdefg ";

Function strrevv ($ str)
{
$ Len = strlen ($ str );
$ Newstr = '';
For ($ I = $ len; $ I >=0; $ I --)
{
$ Newstr. = $ str {$ I };
}
Return $ newstr;
}
$ Showstr = strrevv ($ str );
Echo $ showstr ."
";
------ Solution --------------------
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 ();
/* Store strings into arrays
*/
$ 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 );
// Print_r ($ array );
/* Concatenate strings
*/
$ String = implode ($ array );
Return $ string;
}

$ Str = "lucy, please invite me to dinner. I'm happy today ";
// $ Str = 12345;
// $ Str = "hello, beautiful! ";

Echo str_rev_gb ($ str );
------ Solution --------------------
Http://jiarry.bokee.com/6043558.html can also solve the problem of Chinese character inversion

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.