Lua编解码html转义字符
local function encodeHtmlSpecialChars(str)
local html = {
["<"] = "<",
[">"] = ">",
["&"] = "&",
}
local decstr, _ = string.gsub(tostring(str), "[<>&]", function(char)
return html[char] or char
end)
return decstr
end
local function decodeHtmlSpecialChars(str)
local html = {
["<"] = "<",
[">"] = ">",
["&"] = "&",
}
local rawstr, _ = string.gsub(tostring(str), "%b&;", function(char)
return html[char] or char
end)
return rawstr
end