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 special characters commonly used in HTML

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article introduces the relevant knowledge of "what are the special characters commonly used in HTML". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

HTML special symbol codes include many kinds of unicode, hexadecimal codes (hex code), html entity codes (entity code), and html entities (html entity) as we know them, and corresponding css code for use in the css content attribute.

You can insert hexadecimal codes (hex code), html entity codes (entity code) or html entities (html entity) directly into the HTML tag. When used in the css content attribute, you should use the corresponding css code.

It is important to note that some symbols are displayed differently depending on the font.

In project applications, there are times when you need to convert html and html code. Here are two ways to convert each other:

JavaScript Code:

Function html_encode (str) {var s = ""; if (str.length = = 0) return ""; s = str.replace (/ & / g, "&"); s = s.replace (/ / g, ">"); s = s.replace (/ / g, ""); s = s.replace (/\'/ g, "& apos;"); s = s.replace (/\ "/ g,") S = s.replace (/\ nCompact g, "

"); return s;} function html_decode (str) {var s ="; if (str.length==0) return ""; s = str.replace (/ & / g, "&"); s = s.replace (/ / g, ">"); s = s.replace (/ / g, ""); s = s.replace (/ & apos;/g, "\"); s = s.replace (/ "/ g,"\ ") S = s.replace (/

/ g, "\ n"); return s;}

Conversion can also be achieved using DOM's innerHTML and textContent by dynamically creating a container tag element, such as DIV, setting the string to be converted to the element's innerText, and then returning the element's innerHTML, which is the HTML-encoded string.

JavaScript Code:

Function html_encode (html) {return document.createElement ('div') .appendChild (document.createTextNode (html)) [xss_clean] [xss_clean];} function html_decode (html) {var a = document.createElement (' div'); a [XSS _ clean] = html; return a.textContent;}

This is the end of the content of "what are the special characters commonly used in HTML". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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