Skip to main content
Inspiring
September 19, 2013
Answered

Remove "<p> </p>" code

  • September 19, 2013
  • 3 replies
  • 1152 views

Hi all, I have a difficulty removing this code "<p> </p>" with replace.

The code in the cfdump is:

</p> <p>  </p> <p>

in the html output it is:

<p>

Tijdens de volle maan vanavond wordt een optische illusie zichtbaar die mensen al sinds de tijd van Aristoteles voor een raadsel stelt.</p>

<p>

  </p>

<p>

De maan lijkt een stuk groter te zijn naarmate deze zich dichter bij de horizon bevindt dan wanneer deze hoger aan de hemel staat.</p>

<p>

  </p>

Any idea's?

This topic has been closed for replies.
Correct answer MarcovandenOever

Finally got the solution!

Using a filter function by: http://www.bennadel.com/index.cfm?event=blog.viewcode&id=1155&index=1

I saw that the mysterious empthy space <p> </p> was replaced by <p>&#160;</p>.

Next was a simple:

<cfset text = ReplaceNoCase(text, "<p>&##160;</p>", "", "ALL")>

and all is fine...

So, the bottom line is "know what you are looking for".

3 replies

MarcovandenOeverAuthorCorrect answer
Inspiring
October 1, 2013

Finally got the solution!

Using a filter function by: http://www.bennadel.com/index.cfm?event=blog.viewcode&id=1155&index=1

I saw that the mysterious empthy space <p> </p> was replaced by <p>&#160;</p>.

Next was a simple:

<cfset text = ReplaceNoCase(text, "<p>&##160;</p>", "", "ALL")>

and all is fine...

So, the bottom line is "know what you are looking for".

Inspiring
September 28, 2013

Well, I am really suprised that this is so hard to do, al I can find is info about using a html filter. I really only need to replace "<p>  </p>", why isn't it easily possible with replace code?

Does anyone know of a regex that works for replacing "<p>  </p>" ?

Thanks!

Participating Frequently
September 29, 2013

<cfscript>

string = "<p>Don't Delete Me 1!</p>

<p> 

   </p>

<P>Don't Delete Me 2!</p>

   <p>

               </P>

<p>I hope it doesn't delete me 3!</p>

";

writeOutput( '<textarea>#reReplaceNoCase( string, '<p>[[:space:]]*</p>', "", "ALL")#</textarea>' );

</cfscript>

Inspiring
September 29, 2013

Hi thanks for your reply, your example works perfect, only when I try to use it in my code it doesn't work, here's what I do:

<cfset text = REReplaceNoCase(text, '<p>[[:space:]]*</p>', "", "ALL")>

<cfoutput>#text#</cfoutput>

<cfabort>

giving me:

<p>

Maar stilte hebben we nodig om onszelf te vinden. Weten wie we in werkelijkheid zijn, wat onze missie of doelstelling in dit leven is.</p>

<p>

  </p>

<p>

Stilte geeft ons kracht</p>

Is the cfscript writeoutput treated differently?

Carl Von Stetten
Legend
September 19, 2013

Are you just trying to remove the empty <p></p> tag pairs, or all of the <p></p> tags and their content?

Inspiring
September 19, 2013

Hi thanks for your answer, I am indeed trying just to remove the empthy <p></p> tags, but because there is spave between those tags and around them I have great problems removing it with replace, I guess I need a regular expression?

Carl Von Stetten
Legend
September 19, 2013

Yes, that was going to be my next suggestion, although I couldn't tell you what that RegEx would look like.  Good luck!

-Carl V.