In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you how to flip php, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Php to achieve flipping methods: 1, using strrev () function to achieve English string flipping; 2, through the user-defined selfStrrev method to achieve Chinese string flipping.
This article operating environment: Windows7 system, PHP7.1 version, Dell G3 computer.
PHP user-defined function to realize the function of flipping Chinese
For PHP, when it comes to string flipping, the first thing that comes to mind is the function strrev ().
Definition and usage of strrev
The strrev () function reverses the string.
Grammar
Strrev (string)
Parameters.
String is required. Specifies the string to reverse.
For example:
The output is:! dlroW olleH
The function strrev () is easy to use in English and can flip strings directly, but if it is in Chinese, then it is all garbled.
For example:
The output result is: no one can understand the result of jaundice. Then teacher Yu will share with you how to reverse the Chinese code.
The first method:
Function selfStrrev ($str) {/ / determine whether a character of type utf8 is entered, otherwise exit if (! is_string ($str) | |! mb_check_encoding ($str,'UTF-8') {exit ("input type is not a string of type UTF8");} $array=array (); / / put the string into the array $l=mb_strlen ($str,'UTF-8') / / in the mb_strlen calculation, if the internal code is UTF8, a Chinese character will be calculated as a length of 1 to calculate the for ($revStr. = mb_substr ($str,$i-1,1,'UTF-8'); / / intercept from the last bit, all the way to the first place, and then put it into the new defined string} return $revStr;} $str = "especially handsome in the teacher"; echo selfStrrev ($str)
The output result is: handsome special division is good at
The technology used here is the mb_XXX series function. It should be noted that the mb_XXX series function is not the core function of PHP. Before using it, you need to make sure that php_mbstring.dll is loaded in php.ini, that is, make sure that the line "extension=php_mbstring.dll" exists and is not commented out, otherwise there will be the problem of undefined function.
The above is all the contents of the article "how to flip php". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.