Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the reasons why the parameters passed in php will be garbled?

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you the "php parameters will be garbled reasons", the content is easy to understand, clear, hope to help you solve the doubt, the following let the editor lead you to study and learn the "php parameters will garbled reasons" this article.

Php parameters will be garbled because of inconsistent coding, the solution is to modify the use of uft-8 coding, such as "mb_detect_encoding ($typeName,'CP936,UTF-8')".

This article operating environment: Windows7 system, PHP7.1 version, Dell G3 computer.

Resolution of garbled php parameters

When the website project uses gb2312 as the project coding, because different browsers may have different encoding of Chinese characters, some will encode Chinese as website coding, some will encode Chinese as utf-8, and garbled errors will occur when receiving parameters in the background. A better solution is to recognize the Chinese characters in the parameters and convert them if it is not gb2312.

$typeName = $_ GET ['typeName']; $encode = mb_detect_encoding ($typeName,'CP936,UTF-8'); / / if it is CP936, it is gbk encoding; if it is UTF-8, it is utf-8 encoding if ($encode = =' UTF-8') {/ / then call the function converted to utf-8 encoding, and finally ensure that it is utf-8$ typeName = iconv ("utf-8", "gb2312", $typeName);}

For the sake of website coding and future expansion, it is recommended to use uft-8 coding.

These are all the contents of this article entitled "what are the reasons for garbled parameters in php?" Thank you for your 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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report