-- Convert accented characters from a given string and return HTML entities in the output string. -- by Philippe Lhoste http://Phi.Lho.free.fr -- v. 2.0 -- 2003/06/10 -- Better algorithm, using regular expression -- v. 1.0 -- 2003/04/19 -- Naive implementation -- from http://lua-users.org/files/wiki_insecure/users/PhiLho/3EncodeEntities.lua local entities = { -- ['&'] = "&", ['<'] = "<", ['>'] = ">", -- French entities (the most common ones) ['à'] = "à", ['â'] = "â", ['é'] = "é", ['è'] = "è", ['ê'] = "ê", ['ë'] = "ë", ['î'] = "î", ['ï'] = "ï", ['ô'] = "ô", ['ö'] = "ö", ['ù'] = "ù", ['û'] = "û", ['ÿ'] = "ÿ", ['À'] = "À", ['Â'] = "Â", ['É'] = "É", ['È'] = "È", ['Ê'] = "Ê", ['Ë'] = "Ë", ['Î'] = "Î", ['Ï'] = "Ï", ['Ô'] = "Ô", ['Ö'] = "Ö", ['Ù'] = "Ù", ['Û'] = "Û", ['ç'] = "ç", ['Ç'] = "Ç", ['Ÿ'] = "Ÿ", ['«'] = "«", ['»'] = "»", ['©'] = "©", ['®'] = "®", ['æ'] = "æ", ['Æ'] = "Æ", ['Œ'] = "Œ", -- Not understood by all browsers ['œ'] = "œ", -- Not understood by all browsers } function EncodeEntities3(toEncode) if toEncode == nil or type(toEncode) ~= "string" then return '' end local EncodeToEntities = function (char) local entity = entities[char] if entity == nil then local code = string.byte(char) if code > 127 then entity = string.format("&#%d;", code) end end return entity or char end entities['&'] = "&" -- I will replace '(.)' with '([^%c%s%w%p])' encodedString = string.gsub(toEncode, '(.)', EncodeToEntities) return encodedString end return EncodeEntities3(input)