In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "php how to achieve string garbled flip", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "php how to achieve string garbled flip" bar!
Php to achieve string code-free flipping method: 1, create a sample PHP file and set the encoding to utf8;2, use the mb_strlen function to obtain the length of the utf8 string; 3, the string into an array; 4, the array keystroke name size inversion; 5, the array of individual character elements can be reassembled into a string.
This article operating environment: Windows7 system, PHP7.1 version, DELL G3 computer
How does php achieve string flip without garbled code?
The method to avoid garbled code by implementing Chinese string inversion in PHP:
Today, when the blogger was looking at the PHP interview questions on the Internet, he saw such a question, how to achieve string inversion. At that time, he wondered if there was a built-in function strrev that could achieve this function. Later tried, this function can only reverse English characters, there will be garbled codes in Chinese. The main reason is the coding problem.
In PHP, the utf-8 code is counted as 3 bytes and gb2312 as 2 bytes. Therefore, if we want to achieve some functions of Chinese strings, we must first solve the coding problem.
Today, this function starts from the coding. Let's start with the implemented functions, which are going to be used today:
Is_string () / / determines whether the parameter is a string, which everyone should know that mb_check_encoding () / / is used to check whether the given string belongs to the specified encoding mb_strlen () / / to obtain the string length mb_substr () / / to intercept the characters in the string krsort () / / to sort the array key names from the highest to the lowest.
The above uses three functions at the beginning of mb, and the functions at the beginning of mb are all used to deal with multi-byte strings, mainly to specify string encoding.
Mb_check_encoding () accepts two parameters, the first parameter is a string, the second parameter is to enter a character encoding, and then determine whether the string belongs to the encoding, and return a Bool value. If the second parameter is omitted, it defaults to internal encoding, which can be viewed through mb_internal_encoding ().
Mb_strlen () takes two parameters, the first is the content of the string, and the second is the encoding of the string.
Mb_substr () takes four parameters, the first is the content of the string to be intercepted, the second is the position to start the interception, the third is the length of the intercept, and the fourth is the encoding of the string (in this case, select utf-8, and none of the other encodings will get the correct result).
Then there is the complete code, the brief comments have been marked, in fact, you only need to read it once:
Thank you for your reading, the above is the content of "php how to achieve string code-free flipping". After the study of this article, I believe you have a deeper understanding of how php realizes string code-free flipping, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.