Header Ads Widget

Ticker

6/recent/ticker-posts

LUA: urlencode y urldecode

función urlencode:

1
2
3
4
5
6
local function urlencode (str)
   str = string.gsub (str, "([^0-9a-zA-Z !'()*._~-])", -- locale independent
      function (c) return string.format ("%%%02X", string.byte(c)) end)
   str = string.gsub (str, " ", "+")
   return str
end

función urldecode:

1
2
3
4
5
local function urldecode (str)
   str = string.gsub (str, "+", " ")
   str = string.gsub (str, "%%(%x%x)", function(h) return string.char(tonumber(h,16)) end)
   return str
end

Ejemplo:

1
print( urlencode("http://tutorialspots.com/") )

Resultado:

1
http%3A%2F%2Ftutorialspots.com%2F

Términos de búsqueda recientes:

  • urldecode centos

Publicar un comentario

0 Comentarios