代码拉取完成,页面将自动刷新
// 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.
// Package ghtml provides useful API for HTML content handling.
//
// HTML编码.
package ghtml
import (
"strings"
"html"
"gitee.com/johng/gf/third/github.com/grokify/html-strip-tags-go"
)
// 过滤掉HTML标签,只返回text内容
// 参考:http://php.net/manual/zh/function.strip-tags.php
func StripTags(s string) string {
return strip.StripTags(s)
}
// 本函数各方面都和SpecialChars一样,
// 除了Entities会转换所有具有 HTML 实体的字符。
// 参考:http://php.net/manual/zh/function.htmlentities.php
func Entities(s string) string {
return html.EscapeString(s)
}
// Entities 的相反操作
// 参考:http://php.net/manual/zh/function.html-entity-decode.php
func EntitiesDecode(s string) string {
return html.UnescapeString(s)
}
// 将html中的部分特殊标签转换为html转义标签
// 参考:http://php.net/manual/zh/function.htmlspecialchars.php
func SpecialChars(s string) string {
return strings.NewReplacer(
"&", "&",
"<", "<",
">", ">",
`"`, """,
"'", "'",
).Replace(s)
}
// 将html部分转义标签还原为html特殊标签
// 参考:http://php.net/manual/zh/function.htmlspecialchars-decode.php
func SpecialCharsDecode(s string) string {
return strings.NewReplacer(
"&", "&",
"<", "<",
">", ">",
""", `"`,
"'", "'",
).Replace(s)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。