Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
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
Medium Priority
?
73 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 25

Accepted Solution

by:
dgrafx earned 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

715 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