go 语言把 HTML 实体转换为字符

臭大佬 2022-04-19 19:32:44 343
Go 
简介 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)

    //&lt;p&gt;sfdfg&lt;/p&gt;&lt;p&gt;&lt;img src=&#34;http://localhost:8181/static/upload/image.png&#34; alt=&#34;image.png&#34; /&gt;&lt;/p&gt;

    //<p>sfdfg</p><p><img src="http://localhost:8181/static/upload/image.png"  alt="image.png" /></p>
}