LuaNET, the lua 5.1 api documentation!

How To/Convert title string to url slug

When making your urls looking better, you may want to convert a title to a url-slug.

An url-slug is in common a string containing only alphanumeric letters and ‘-’. Following lua function converts a normal title string to a url-slug.
Code
function toSlug(str)
return string.gsub(string.gsub(str,"[^ A-Za-z]",""),"[ ]+","-")
end


The toSlug function also replaces multiple spaces with one ‘-‘ only.
Comments
© 2007 DracoBlue :: Valid XHTML, CSS, RSS Powered by SMF 1.1.5 | SMF © 2006-2008, Simple Machines LLC | SourceNet © 2007, DracoBlue :: Page created in 0.227 seconds with 18 queries.