Browse Source

html escape & unescape

ls 5 years ago
parent
commit
b17acbfe1f
1 changed files with 27 additions and 0 deletions
  1. 27 0
      web/html.go

+ 27 - 0
web/html.go

@@ -0,0 +1,27 @@
+package web
+
+import (
+	"strings"
+)
+
+// HTMLUnEscape html special char convert
+// 	 &quot; to space, &amp; to &, &lt; to <, &gt; to >
+func HTMLUnEscape(url string) string {
+	s := strings.Replace(url, "&quot;", "\"", -1)
+	s = strings.Replace(s, "&amp;", "&", -1)
+	s = strings.Replace(s, "&lt;", "<", -1)
+	s = strings.Replace(s, "&gt;", ">", -1)
+
+	return s
+}
+
+// HTMLEscape html special char convert
+// 	 space to &quot;, & to &amp;, < to &lt;, > to &gt;
+func HTMLEscape(url string) string {
+	s := strings.Replace(url, "\"", "&quot;", -1)
+	s = strings.Replace(s, "&", "&amp;", -1)
+	s = strings.Replace(s, "<", "&lt;", -1)
+	s = strings.Replace(s, ">", "&gt;", -1)
+
+	return s
+}