当前位置:在线工具>转换相关>HTML实体字符转换
手机访问

转换HTML实体字符 / HTML实体字符反转


HTML实体字符说明

有些字符,像(<)这类的,对HTML(标准通用标记语言下的一个应用)来说是有特殊意义的,所以这些字符是不允许在文本中使用的。要在HTML中显示(<)这个字符,我们就必须使用实体字符。

字符描述实体名称实体编号
空格&nbsp;
<小于号&lt;<
>大于号&gt;>
&和号&amp;&
"引号&quot;"
'撇号&apos; (IE不支持)'
&cent;¢
&pound;£
人民币&yen;¥

Example PHP

示例 #1 htmlentities() 例子
<?php
$str = "A 'quote' is bold";

echo htmlentities($str);
echo htmlentities($str, ENT_QUOTES);
示例 #2 html_entity_decode Decoding HTML entities
 <?php $orig = "I'll \"walk\" the dog now"; // 将字符转换为 HTML 转义字符 $a = htmlentities($orig); // 将转义字符还原成 HTML 字符 $b = html_entity_decode($a); 

Example Go

示例 #1 Go 将字符转换为HTML转义字符
package main

import (
"fmt"
"html"
)

func main() {
input := "Hello, World!"
escaped := html.EscapeString(input)
fmt.Println(escaped)
}
示例 #2 Go 将HTML转义字符还原成字符
 package main import ( "fmt" "html" ) func main() { escapedStr := "<b>Hello, World!</b>" unescapedStr := html.UnescapeString(escapedStr) fmt.Println(unescapedStr) }