?
Ce document utilise Manuel du site Web PHP chinois Libérer
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個這樣的字符:<,>,&,'和“。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使像“<”這樣的實體變?yōu)椤?lt;”。它不像EscapeString轉(zhuǎn)義那樣描繪了更多的實體。例如,“á”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)實現(xiàn)了數(shù)據(jù)驅(qū)動的模板,以便在代碼注入過程中安全地生成HTML輸出。 |