HTML 实体转换 HTML Entity Encode/Decode
实体编码/解码(&、<、>、"、' 等),用于防止字符在 HTML 中被误解析,或将实体还原为可读文本。
Encode/decode HTML entities (like &, <) to avoid being interpreted as HTML, or to restore readable text.
1. 输入参数 · Input
3. 使用说明 · Notes
-
什么是 HTML 实体? · What are HTML entities?
HTML 实体(Entity)是一种“字符的转义写法”,用来表示那些在 HTML 中有特殊含义的符号, 比如 <、>、&、引号等。
An entity is an escaped representation of a character, especially those with special meaning in HTML (like < > & and quotes). -
为什么需要编码? · Why encode?
当你把一段文本直接放进 HTML(博客/论坛/富文本/模板)时,浏览器会“尝试解析”其中的标签与语法。
例如输入 hi,可能会被渲染成粗体,而不是原样显示。
编码后会变成 <b>hi</b>,浏览器就只会当作普通文本显示。
If you paste raw text into HTML, the browser may interpret it as markup. Encoding turns it into safe text so it displays literally. -
什么时候需要解码? · When decode?
你在日志、接口返回、数据库字段、SEO 抓取结果中,可能会看到实体形式(如 &)。 解码可以把它们还原为可读字符,方便排错、对比与二次处理。
Decode when you need to read or process text that already contains entities (e.g., from logs, API responses, crawlers). -
“最小安全编码” vs “尽量全量编码” · Minimal vs More encoding
Minimal 通常只编码 &、<、>(可选引号), 适合绝大多数展示场景,输出更短、更可读。
All 会把更多符号变成实体/数字实体,更适合:嵌入属性值、避免任何歧义、或需要严格一致输出的场景。
Minimal is shorter and readable; More encoding is stricter and reduces ambiguity for embedding into attributes/templates. -
数字实体:十进制/十六进制 · Numeric entities
形如 <(十进制)或 <(十六进制), 都表示字符 <。本工具在解码时会识别两种形式。
Both decimal (<) and hex (<) forms are supported in decoding. -
安全提醒 · Safety reminder
这类工具用于“展示/转义/还原文本”,不是用来绕过安全机制。若你的页面会把结果再插入 HTML 并执行, 请确保你理解 XSS 风险,并使用可信的渲染策略(例如插入为文本节点而非 innerHTML)。
This tool helps with escaping/unescaping. If you re-inject output into HTML as executable markup, understand XSS risks and prefer text insertion over innerHTML.
说明:本工具在浏览器本地运行,不会上传你的文本内容。结果仅用于排版、调试与学习参考。
Note: Runs locally in your browser; your input is not uploaded. Results are for formatting, debugging, and learning.
