• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

smarter "REPLACE"

LEGEND ,
Jul 06, 2006 Jul 06, 2006

Copy link to clipboard

Copied

I need help on "Replace" function to make it work smarter. I need to clean
all tags from the database records because the page should not be formatted.
Using a series of "Replace" function as shown below is not comprehensive and
not pretty. Is there a way to remove all tags in one shot?

<cfset content_result = "#Replace(content_result, "<br>", " ", "ALL")#">
<cfset content_result = "#Replace(content_result, "</br>", " ", "ALL")#">
<cfset content_result = "#Replace(content_result, "<br />", " ", "ALL")#">
<cfset content_result = "#Replace(content_result, "<p>", " ", "ALL")#">
<cfset content_result = "#Replace(content_result, "</p>", " ", "ALL")#">
<cfset content_result = "#Replace(content_result, "<h2>", " ", "ALL")#">
<cfset content_result = "#Replace(content_result, "</h2>", ". ", "ALL")#">
<cfset content_result = "#Replace(content_result, "<h3>", " ", "ALL")#">
<cfset content_result = "#Replace(content_result, "</h3>", ". ", "ALL")#">
<cfset content_result = "#Replace(content_result, "<h4>", " ", "ALL")#">
<cfset content_result = "#Replace(content_result, "</h4>", ". ", "ALL")#">
<cfset content_result = "#Replace(content_result, "<ul>", " ", "ALL")#">
<cfset content_result = "#Replace(content_result, "</ul>", ". ", "ALL")#">
<cfset content_result = "#Replace(content_result, "<li>", " ", "ALL")#">
<cfset content_result = "#Replace(content_result, "</li>", ". ", "ALL")#">


TOPICS
Advanced techniques

Views

274

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 06, 2006 Jul 06, 2006

Copy link to clipboard

Copied

You could use REReplace( ), the regular expression version of Replace( ). It would be faster than what you have, but it would probably be uglier. 🙂

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 06, 2006 Jul 06, 2006

Copy link to clipboard

Copied

LATEST
> Is there a way to remove all tags in one shot?

<!--- Code to remove all tags from your content_result --->
<cfscript>
content_result = REReplaceNoCase(content_result,"<[^>]*>","","ALL");
</cfscript>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation