htmlEscape
htmlEscape
函数主要是用来将所给字符串或者字节数组进行 html 实体编码,并输出编码后的字符串
函数原型
func htmlEscape(s1 string, mode string, isAll bool) string
func htmlEscape(b1 bytes, mode string, isAll bool) string
参数介绍
参数名称 | 参数介绍 |
---|---|
s1/b1 | 为需要进行编码的字符串或者字节数组 |
mode | html 实体编码的格式,支持named , numeric , hex 三种模式 |
isAll | 是否进行全字符编码 |
named模式支持将符号等特殊字符编码为特定的名称,numeric会将字符编码为10进制模式,hex会将字符编码为16进制模式
举例
待转换数据 | 转换语句 | 输出结果 |
---|---|---|
"\"Fran & Freddie's Diner\" <tasty@example.com>" | htmlEscape("\"Fran & Freddie's Diner\" <tasty@example.com>", "named", false) | "Fran & Freddie's Diner" <tasty@example.com> |
b"\"Fran & Freddie's Diner\" <tasty@example.com>" | htmlEscape("\"Fran & Freddie's Diner\" <tasty@example.com>", "named", true) | "Fran & Freddie's Diner" <tasty@example.com> |
"\"Fran & Freddie's Diner\" <tasty@example.com>" | htmlEscape("\"Fran & Freddie's Diner\" <tasty@example.com>", "numeric", true) | "Fran & Freddie's Diner" <tasty@example.com> |
"\"Fran & Freddie's Diner\" <tasty@example.com>" | htmlEscape("\"Fran & Freddie's Diner\" <tasty@example.com>", "numeric", false) | "Fran & Freddie's Diner" <tasty@example.com> |
"\"Fran & Freddie's Diner\" <tasty@example.com>" | htmlEscape("\"Fran & Freddie's Diner\" <tasty@example.com>", "hex", true) | "Fran & Freddie's Diner" <tasty@example.com> |
"|\\/,asd.{55r](" | htmlEscape("|\\/,asd.{55r](", "named", false) | |\/,asd.{55r]( |
Was this page helpful?