?
This document uses PHP Chinese website manual Release
import "html"
概觀
索引
示例
子目錄
包html提供了用于轉(zhuǎn)義和修改HTML文本的功能。
func EscapeString(s string) string
func UnescapeString(s string) string
EscapeString UnescapeString
entity.go escape.go
func EscapeString(s string) string
EscapeString將特殊字符(如“<”)轉(zhuǎn)義為“<”。它只能逃脫5個(gè)這樣的字符:<,>,&,'和“。UnescapeString(EscapeString(s))== s總是成立,但反過來并不總是正確的。
package mainimport ("fmt""html")func main() {const s = `"Fran & Freddie's Diner" <tasty@example.com>` fmt.Println(html.EscapeString(s))}
func UnescapeString(s string) string
UnescapeString使像“<”這樣的實(shí)體變?yōu)椤?lt;”。它不像EscapeString轉(zhuǎn)義那樣描繪了更多的實(shí)體。例如,“á”unescape到“á”,就像“á”和“á”一樣。UnescapeString(EscapeString(s))== s總是成立,但反過來并不總是正確的。
package mainimport ("fmt""html")func main() {const s = `"Fran & Freddie's Diner" <tasty@example.com>` fmt.Println(html.UnescapeString(s))}
名稱 | 概要 |
---|---|
模板 | 包模板(html / template)實(shí)現(xiàn)了數(shù)據(jù)驅(qū)動(dòng)的模板,以便在代碼注入過程中安全地生成HTML輸出。 |