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?
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;
}
Echo str_rev_gb ($ str );
------ Solution --------------------
Http://jiarry.bokee.com/6043558.html can also solve the problem of Chinese character inversion
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