In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "how to solve the problem of Chinese garbled code in Php mbsubstr". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to solve the problem of Chinese garbled code in Php mbsubstr".
1. Use the mb_substr () interception of the mbstring extension library.
2. Solve the garbled code problem through the custom "function sub_str () {...}" method.
You can use the function mb_substr () / mb_strcut (). The use of mb_substr () / mb_strcut () is similar to substr (), except that one more parameter is added at the end of mb_substr () / mb_strcut to set the encoding of the string.
But most servers do not open php_mbstring.dll, so you need to open php_mbstring.dll in php.ini.
Echo mb_substr ("php Chinese character encode", 0jue 4, "utf-8")
If the last encoding parameter is not specified, it will be three bytes into one Chinese, which is the characteristic of utf-8 coding. If you add the utf-8 character set description, it is intercepted in a word unit.
When using, you should pay attention to the encoding of the php file and the coding of the web page display. To use this mb_substr method, you need to know the encoding of the string in advance, and if you don't know the encoding, you need to judge. The mbstring library also provides mb_check_encoding to verify the string encoding, but it is not perfect.
PHP comes with several string intercepting functions, among which substr and mb_substr are commonly used. When the former deals with Chinese, GBK is 2 length units and UTF is 3 length units. After the latter is specified, one Chinese language is 1 length unit.
Substr sometimes truncates 3 or half of Chinese characters and displays garbled codes. Relatively speaking, mb_substr is more suitable for us to use. But sometimes mb_substr doesn't seem to work so well. For example, I want to display a brief message of a small picture. Five Chinese words are just right. If more than five, intercept the first four and add "…" It is no problem to deal with Chinese in this way, but it is too short to intercept English or numbers.
Thank you for your reading, the above is the content of "how to solve the problem of Chinese garbled code in Php mbsubstr". After the study of this article, I believe you have a deeper understanding of how to solve the problem of Chinese garbled code in Php mbsubstr. 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: 264
*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.