Solved

How can I keep <sup>whatever</sup> & <sub>whatever</sub> html tags in my coldfusion string but get rid of all other html tags?

Posted on 2016-08-06
5
52 Views
Last Modified: 2016-08-07
How can I keep <sup>whatever</sup> & <sub>whatever</sub> html tags in my coldfusion string but get rid of all other html tags?
0
Comment
Question by:brihol44
  • 3
  • 2
5 Comments
 
LVL 25

Accepted Solution

by:
dgrafx earned 500 total points
ID: 41746371
Right before you strip the tags replace the sup tags with some character that doesn't exist in the string like a [ and a ] so it looks like
[sup] and [/sup].
Then strip the tags.
Then replace the [sup] and [/sup] 
with <sup> and </sup>.

Open in new window

0
 

Author Comment

by:brihol44
ID: 41746482
Nice! Have it working but is there a way to condense this code wise? Is there a delimiter to do something like... <cfset editedValue = REReplace(editedValue, "<sup>|</sup>", "|", "ALL")> (only for conveying to you) to condense the code? Or is this just handled like "ReReplace(REReplace(...." just curious if there's a pre-defined delimiter.

Thank you!

<cfset editedValue = "<sup>Hello!</sup>" >
<cfset editedValue = REReplace(editedValue, "<sup>", "[sup]", "ALL")>
<cfset editedValue = REReplace(editedValue, "</sup>", "[/sup]", "ALL")>
<cfset editedValue = REReplace(editedValue, "<sub>", "[sub]", "ALL")>
<cfset editedValue = REReplace(editedValue, "</sub>", "[/sub]", "ALL")>
<cfset editedValue = REReplace(editedValue, "(<[^>]*>)", "", "ALL")>
<cfset editedValue = Replace(editedValue, "[sup]", "<sup>", "ALL")>
<cfset editedValue = Replace(editedValue, "[/sup]", "</sup>", "ALL")>
<cfset editedValue = Replace(editedValue, "[sub]", "<sub>", "ALL")>
<cfset editedValue = Replace(editedValue, "[/sub]", "</sub>", "ALL")>

Open in new window

0
 

Author Closing Comment

by:brihol44
ID: 41746485
Thank you!
0
 

Author Comment

by:brihol44
ID: 41746487
oops. my example was not wrapped by code tags...
<cfset editedValue = REReplace(editedValue, "<sup>|</sup>", "[sup]|[/sup]", "ALL")>

Open in new window

0
 
LVL 25

Expert Comment

by:dgrafx
ID: 41746589
Here ya go!

<b>Original:</b><br />
<cfsavecontent variable="editedValue">
<b>This</b> is some <sub>testing</sub> <u>text</u>. <sup>Hello</sup>!<br>
I walk <sub>that</sub> a <b>child</b> <sup>might</sup> <i>live</i> ...
</cfsavecontent>
#variables.editedValue#<br />
<hr>

<b>Preserve sub & sup:</b><br>
<cfset editedValue = ReplaceNoCase(ReplaceNoCase(ReplaceNoCase(ReplaceNoCase(variables.editedValue,
		"</sub>","[/sub]","ALL"),"<sub>","[sub]","ALL"),"</sup>","[/sup]","ALL"),"<sup>","[sup]","ALL")
	>
#variables.editedValue#<br />
<hr>

<b>Strip tags:</b><br>
<cfset editedValue = ReReplace(variables.editedValue, "(,)|(<[^>]*>)", "", "All")>
#variables.editedValue#<br>
<hr>

<b>Final:</b><br>
<cfset editedValue = ReplaceNoCase(ReplaceNoCase(ReplaceNoCase(ReplaceNoCase(variables.editedValue,
		"[/sub]","</sub>","ALL"),"[sub]","<sub>","ALL"),"[/sup]","</sup>","ALL"),"[sup]","<sup>","ALL")
	>
#variables.editedValue#

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now