Stripping html tags (was Re: Problem with revExecuteSQL - More)
Jim Ault
JimAultWins at yahoo.com
Fri Nov 2 12:23:23 EDT 2007
On 11/2/07 3:42 AM, "Eric Chatonet" <eric.chatonet at sosmartsoftware.com>
wrote:
> Hi Jim and Dave,
>
> Sorry I did not read this thread too much...
> I should have :-)
>
> Not sure that I understand Dave's request because I have not read all
> novels posted in this thread :-)
> Probably, Jim makes an allusion to the StripTags function that is in
> the script of the unique card of the Rev Search Engine?
> I hope so...
Found the handler: this will strip tags and parse things like "'"
Caution: It has been modified to work with a particular app I wrote, so step
through it and adjust to your recipe.
--watch out for the word wrap that your email client may have used
function StripTags pHtml
local tRegex,tPrevText
get ("é,à,ç")
get it & (",>,<,ê")
get it & (",è,©,•")
get it & (",',·,&")
-- add more chars if you wish, then...
constant kHtml = it
constant kConvertedHtml = "é,à,ç,>,<,ê,è,©"
--using contants means you cannot accidentally
-- modify these vars and damage the results
-----
replace numtochar(13) with empty in pHtml
replace tab with empty in pHtml
replace "<td" with numtochar(160)&"<td" in pHtml
-----
put replacetext(pHtml,"(?Usi)<SCRIPT.*</SCRIPT>","") into pHtml
put replacetext(pHtml,"(?Usi)<STYLE>.*</STYLE>","") into pHtml
put replacetext(pHtml,"(?Usi)<\?.*\?>","") into pHtml
-----
replace " " with space in pHtml
replace "<BR>" with return in pHtml
replace "<p>" with return in pHtml
-----
put "<[^><]*>" into tRegex
put replacetext(pHtml,tRegex,"") into pHtml
put replacetext(pHtml,tRegex,"") into pHtml
----- repeat replacements until there are no changes
repeat until tPrevText is pHtml
put pHtml into tPrevText
put replacetext(pHtml," +",space) into pHtml
put replacetext(pHtml,"^ ","") into pHtml
end repeat
-----
replace (space & return) with return in pHtml
replace (return & space) with return in pHtml
filter pHtml without empty
replace numtochar(160) with empty in pHtml
-----
replace """ with quote in pHtml
repeat with i = 1 to the number of items of kHtml
replace item i of kHtml with item i of kConvertedHtml in pHtml
end repeat
-----
--put pHtml into msg --let's you see the result in the msg box
return pHtml
end StripTags
Jim Ault
Las Vegas
More information about the use-livecode
mailing list