lua对url字符进行编解码

 

 

local function urlEncode(s)
  s = string.gsub(s, "([^%w%.%- ])", function(c) return string.format("%%%02X", string.byte(c)) end)
  return string.gsub(s, " ", "+")
end
 
 
local function urlDecode(s)
  s = string.gsub(s, '%%(%x%x)', function(h) return string.char(tonumber(h, 16)) end)
  return s
end

print(urlDecode('muser01%40yx.com'))
#结果:muser01@yx.com

转自:https://blog.csdn.net/yetyongjin/article/details/120848024

 

posted on 2023-06-10 17:48  momingliu11  阅读(297)  评论(0编辑  收藏  举报