local entities = { -- ['&'] = "&", ['<'] = "<", ['>'] = ">", -- French entities (the most common ones) ['�'] = "à", ['�'] = "â", ['�'] = "é", ['�'] = "è", ['�'] = "ê", ['�'] = "ë", ['�'] = "î", ['�'] = "ï", ['�'] = "ô", ['�'] = "ö", ['�'] = "ù", ['�'] = "û", ['�'] = "ÿ", ['�'] = "À", ['�'] = "Â", ['�'] = "É", ['�'] = "È", ['�'] = "Ê", ['�'] = "Ë", ['�'] = "Î", ['�'] = "Ï", ['�'] = "Ô", ['�'] = "Ö", ['�'] = "Ù", ['�'] = "Û", ['�'] = "ç", ['�'] = "Ç", ['�'] = "Ÿ", ['�'] = "«", ['�'] = "»", ['�'] = "©", ['�'] = "®", ['�'] = "æ", ['�'] = "Æ", ['�'] = "Œ", -- Not understood by all browsers ['�'] = "œ", -- Not understood by all browsers } function EncodeEntities(string) if string == nil or type(string) ~= "string" then return '' end local EncodeHighAscii = function (char) local code = strbyte(char) if code > 127 then return format("&#%d;", code) else return char end end local encodedString = string -- First encode '&' char, to avoid re-encoding already encoded chars encodedString = gsub(encodedString, '&', "&") -- Encode known entities for char, entity in %entities do -- Lua 4.0 and before, use %entities encodedString = gsub(encodedString, char, entity) end encodedString = gsub(encodedString, '(.)', EncodeHighAscii) return encodedString end