PtokaX forum

Development Section => Extensions for PtokaX Lua => Topic started by: Leun on 02 February, 2007, 14:47:35

Title: convert html to characters by using pxwsa
Post by: Leun on 02 February, 2007, 14:47:35
Hi,

In one of my scripts I use pxwsa to get info from a website.
But some characters had a html code, so you need to convert it, what cost lots of time,
So a little help;


for a,b in ConvertHTML do   
    if sDirector then 
         sDirector= string.gsub(sDirector,a,b);   
    end  
end

ConvertHTML = {   
["""] = '"', ["&"] = "&", ["À"] = "?", ["Á"] = "?",
["Â"] = "?", ["Ã"] = "?", ["Ä"] = "?", ["Å"] = "?",
["Æ"] = "?", ["Ç"] = "?", ["È"] = "?", ["É"] = "?",
["Ê"] = "?", ["Ë"] = "?", ["Ì"] = "?", ["Í"] = "?",
["Î"] = "?", ["Ï"] = "?", ["Ð"] = "?", ["Ñ"] = "?",
["Ò"] = "?", ["Ó"] = "?", ["Ô"] = "?", ["Õ"] = "?",
["Ö"] = "?", ["Ø"] = "?", ["Ù"] = "?", ["Ú"] = "?",
["Û"] = "?", ["Ü"] = "?", ["Ý"] = "?", ["Þ"] = "?",
["ß"] = "?", ["à"] = "?", ["á"] = "?", ["â"] = "?",
["ã"] = "?", ["ä"] = "?", ["å"] = "?", ["æ"] = "?",
["ç"] = "?", ["è"] = "?", ["é"] = "?", ["ê"] = "?",
["ë"] = "?", ["ì"] = "?", ["í"] = "?", ["î"] = "?",
["ï"] = "?", ["ð"] = "?", ["ð"] = "?", ["ñ"] = "?",
["ò"] = "?", ["ó"] = "?", ["ô"] = "?", ["õ"] = "?",
["ö"] = "?", ["÷"] = "?", ["ø"] = "?", ["ù"] = "?",
["ú"] = "?", ["û"] = "?", ["ü"] = "?", ["ý"] = "?",
["þ"] = "?", ["ÿ"] = "?",
}


greetz
Title: Re: convert html to characters by using pxwsa
Post by: bastya_elvtars on 02 February, 2007, 17:16:41
Isn't this easier and faster with string.gfind("(%&%#.+%:)") and hashing?
Title: Re: convert html to characters by using pxwsa
Post by: Leun on 03 February, 2007, 11:58:11
Quote from: bastya_elvtars on 02 February, 2007, 17:16:41
Isn't this easier and faster with string.gfind("(%&%#.+%:)") and hashing?

Yes you're right, thnx for the tip  :)
Title: Re: convert html to characters by using pxwsa
Post by: bastya_elvtars on 03 February, 2007, 15:01:52
Care to show us your work then? :)
Title: Re: convert html to characters by using pxwsa
Post by: Leun on 03 February, 2007, 16:29:38
something like this?


ConvertFeed = function(fFeed)
for txt in string.gfind(fFeed,"(%&%#.+%;)") do
for a,b in ConvertHTML do   
fFeed = string.gsub(txt,a,b)   
end  
end
return fFeed
end
Title: Re: convert html to characters by using pxwsa
Post by: bastya_elvtars on 03 February, 2007, 20:10:43
No, fFeed[txt]