go 语言把 HTML 实体转换为字符
简介
go 语言把 HTML 实体转换为字符
代码
package main
import (
"fmt"
"html"
)
func main() {
htmls := "<p>sfdfg</p>\n<p><img src=\"http://localhost:8181/static/upload/image.png\" alt=\"image.png\" /></p>\n"
s := html.EscapeString(htmls)
us := html.UnescapeString(s)
fmt.Println(s)
fmt.Println(us)
//<p>sfdfg</p><p><img src="http://localhost:8181/static/upload/image.png" alt="image.png" /></p>
//<p>sfdfg</p><p><img src="http://localhost:8181/static/upload/image.png" alt="image.png" /></p>
}