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--
Editor to share with you the solution to htmlentities garbled in 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 htmlentities garbled solution: 1, use "htmlentities ($str,ENT_COMPAT," GB2312 ")"; 2, output "htmlspecialchars ($str)".
This article operating environment: Windows7 system, PHP7.1 version, Dell G3 computer.
The problem that Chinese cannot be queried due to htmlentities in php
In php, htmlspecialchars converts special characters to HTML format, while htmlentities converts all characters into HTML strings. Let me briefly introduce them respectively.
Htmlentities usage
$str = "John & 'Adams'"; echo htmlentities ($str, ENT_COMPAT); echo ""; echo htmlentities ($str, ENT_QUOTES); echo ""; echo htmlentities ($str, ENT_NOQUOTES);? > John &' Adams' John & 'Adams' John &' Adams'
Browser output:
Htmlspecialchars usage
& (and) turn into &
"(double quotation marks) converted to"
< (小于) 转成 < >(greater than) convert to >
Example
$str = "John & 'Adams'"; echo htmlspecialchars ($str, ENT_COMPAT); echo ""; echo htmlspecialchars ($str, ENT_QUOTES); echo ""; echo htmlspecialchars ($str, ENT_NOQUOTES);? >
The difference between them
The function of both functions is to convert characters to HTML character encodings, especially url and code strings. Prevents character tags from being executed by the browser. There is no difference when using Chinese, but htmlentities formats Chinese characters so that Chinese input is garbled.
Htmlentities converts all html tags, htmlspecialchars only formats &'"
< 和 >These special symbols
Effect:
$str = 'test page'
Echo 'htmlentities specifies the GB2312 code:' .htmlentities ($str,ENT_COMPAT, "GB2312").'
Echo 'htmlentities does not specify the code:' .htmlentities ($str).'
$str = 'test page'
Echo htmlspecialchars ($str).''
The above is all the contents of this article entitled "Solutions to htmlentities garbled codes in 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.