From e4f8672814a5ee1215107a8905cc63bdd5fa335b Mon Sep 17 00:00:00 2001 From: wuyongyuan <270458160@qq.com> Date: Thu, 14 Oct 2021 20:05:59 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E5=9C=A8=E5=88=87=E7=89=87=E4=B8=AD?= =?UTF-8?q?=E5=AF=B9=E5=BA=94=E7=B4=A2=E5=BC=95=E5=92=8C=E4=B8=8D=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E6=8E=92=E5=BA=8Fmap=E5=AD=97=E5=85=B8=E6=8B=BC?= =?UTF-8?q?=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- map.go | 26 ++++++++++++++++++++++++++ string.go | 20 ++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/map.go b/map.go index 91434b9..6343157 100644 --- a/map.go +++ b/map.go @@ -119,3 +119,29 @@ func HttpBuildQuery(data map[string]string) string { return strings.Trim(query, "&") } + +/** + * 对map进行拼接 + * @param data map[string]string + * @2021/10/14 + * @wyy + */ +func HttpBuildStringQuery(data map[string]string) string { + + keySlice := []string{} + + for k, _ := range data { + keySlice = append(keySlice, k) + } + // sort.Strings(keySlice) //排序字符串 + + var query string + + for _, value := range keySlice { + if value != "" && data[value] != "" { + query += StringJoin(value, "=", data[value], "&") + } + } + + return strings.Trim(query, "&") +} diff --git a/string.go b/string.go index 49da990..b674a23 100755 --- a/string.go +++ b/string.go @@ -203,6 +203,26 @@ func IsInStringArray(arr []string, str string) bool { return isIn } +/** + * 字符串在字符切片中对应索引 + */ +func InStringArrayIndex(arr []string, str string) int { + // var isIn bool = false + length := len(arr) + if length < 1 { + return -1 + } + var index int = -1 + for k, item := range arr { + if item == str { + // isIn = true + index = k + break + } + } + return index +} + /* * 删除多余空格 * 2019/05/05 From a2aaf6a7b987e710e55d8f5b96b615f3b0c05638 Mon Sep 17 00:00:00 2001 From: wuyongyuan <270458160@qq.com> Date: Thu, 14 Oct 2021 20:29:00 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9HttpBuildStringQuery?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- map.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/map.go b/map.go index 6343157..435f465 100644 --- a/map.go +++ b/map.go @@ -2,6 +2,7 @@ package helper import ( "errors" + "net/url" "sort" "strings" ) @@ -121,7 +122,7 @@ func HttpBuildQuery(data map[string]string) string { } /** - * 对map进行拼接 + * 对map字典按照顺序进行拼接,并且把每个value进行类urlencode * @param data map[string]string * @2021/10/14 * @wyy @@ -139,7 +140,7 @@ func HttpBuildStringQuery(data map[string]string) string { for _, value := range keySlice { if value != "" && data[value] != "" { - query += StringJoin(value, "=", data[value], "&") + query += StringJoin(value, "=", url.QueryEscape(data[value]), "&") } } From 1a695482862bba1109ae8ba40759d31afa71db61 Mon Sep 17 00:00:00 2001 From: listen <494177603@qq.com> Date: Wed, 20 Oct 2021 11:47:17 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=8A=A0=E5=85=A5=E8=BF=87=E6=BB=A4html?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- string.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/string.go b/string.go index c48fb45..8588724 100755 --- a/string.go +++ b/string.go @@ -271,3 +271,27 @@ func UrlJoin(host, url string) string { return StringJoin(host, url) } + + +/** + * 去除字符串的html标签 + * @2021/10/20 + */ +func TrimHtml(src string) string { + //将HTML标签全转换成小写 + re, _ := regexp.Compile("\\<[\\S\\s]+?\\>") + src = re.ReplaceAllStringFunc(src, strings.ToLower) + //去除STYLE + re, _ = regexp.Compile("\\") + src = re.ReplaceAllString(src, "") + //去除SCRIPT + re, _ = regexp.Compile("\\") + src = re.ReplaceAllString(src, "") + //去除所有尖括号内的HTML代码,并换成换行符 + re, _ = regexp.Compile("\\<[\\S\\s]+?\\>") + src = re.ReplaceAllString(src, "\n") + //去除连续的换行符 + re, _ = regexp.Compile("\\s{2,}") + src = re.ReplaceAllString(src, "\n") + return strings.TrimSpace(src) +}