mirror of
https://gitee.com/johng/gf.git
synced 2024-12-04 13:18:01 +08:00
33 lines
814 B
Go
33 lines
814 B
Go
// Copyright 2017 gf Author(https://gitee.com/johng/gf). All Rights Reserved.
|
|
//
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
// If a copy of the MIT was not distributed with this file,
|
|
// You can obtain one at https://gitee.com/johng/gf.
|
|
|
|
// HTML编码
|
|
package ghtml
|
|
|
|
import "strings"
|
|
|
|
// 将html中的特殊标签转换为html转义标签
|
|
func SpecialChars(s string) string {
|
|
return strings.NewReplacer(
|
|
"&", "&",
|
|
"<", "<",
|
|
">", ">",
|
|
`"`, """,
|
|
"'", "'",
|
|
).Replace(s)
|
|
}
|
|
|
|
// 将html转义标签还原为html特殊标签
|
|
func SpecialCharsDecode(s string) string {
|
|
return strings.NewReplacer(
|
|
"&", "&",
|
|
"<", "<",
|
|
">", ">",
|
|
""", `"`,
|
|
"'", "'",
|
|
).Replace(s)
|
|
}
|