Selectively removing HTML from Foxpro tables

      No Comments on Selectively removing HTML from Foxpro tables

I was working with some web developers upgrading a VFP data driven website. There were many HTML tags and references in memo fields that needed to be removed when moving to the new site design. I didn’t want to remove ALL of the HTML tags, but just some. I modified some code that I found and these little snippets worked out nicely.

lcHTML = MyTable.MyMemoFieldWithHTML
lcHTML = RemoveHTMLTag( lcHTML, "<font", [<span class="qs-bold-12-blue">] )
lcHTML = RemoveHTMLTag( lcHTML, "</font", "</span>" )
lcHTML = RemoveHTMLTag( lcHTML, "<strong", "" )
lcHTML = RemoveHTMLTag( lcHTML, "</strong", "" )

*!* Program: RemoveHTMLTag
*!* Author: CULLY Technologies, LLC
*!* Date: 12/10/12 08:30:30 PM
*!* Copyright:
*!* Description:
*!* Revision Information:
FUNCTION RemoveHTMLTag( lcHTML, lcTag, lcReplacement )
lcHTMLSource = lcHTML
nTagCount = OCCURS( lcTag, lcHTMLSource )
nNewTagCount = nTagCount
DO WHILE nTagCount > 0
nOpenLoc = AT(lcTag, lcHTMLSource )
lcTemp = SUBSTR( lcHTMLSource, nOpenLoc+1 )
nCloseLoc = AT(">", lcTemp ) + nOpenLoc + 1
cTextToRemove = SUBSTR( lcHTMLSource, nOpenLoc, nCloseLoc - nOpenLoc )
lcHTMLSource = STRTRAN( lcHTMLSource, cTextToRemove, lcReplacement )
nNewTagCount = OCCURS( lcTag, lcHTMLSource )
IF nNewTagCount = nTagCount && We're making sure we're still removing tags and that the HTML isn't invalid which would create an endless loop.
nTagCount = nNewTagCount

I hope this helps someone out.

Leave a Reply