Jump to content

Repair IE RTE HTML with RegExp


butzman

Recommended Posts

Hi,

 

i've got a problem with the HTML generated from IE with designMode on.

 

The internet explorer generates invalid html like this:

 

<P><STRONG> </P>
<P> </P>
<P> </P></STRONG>
<P> </P>
<P><STRONG> </P>
<P> </P>
<P> </P></STRONG>

 

or like this...

 

<P><STRONG><EM>Lorem ipsum...</P>
<P> </P></EM></STRONG>

 

I need to fix that HTML-Code on serverside to get valid html that should look like:

Example 1: ( or remove all STRONG tags )

<P><STRONG> </STRONG></P>
<P><STRONG> </STRONG></P>
<P><STRONG> </STRONG></P>
<P> </P>
<P><STRONG> </STRONG></P>
<P><STRONG> </STRONG></P>
<P><STRONG> </STRONG></P>

 

Example 2:

<P><STRONG><EM>Lorem ipsum...</EM></STRONG></P>
<P> </P>

 

I tried to create several RegExp to match this certain HTML. But my regular expressions failed or destroyed the html by too much recursion or greedy behavior.

 

I would be very thankful, if someone could help me. I just need to get valid html and keep the formatting on the plain text. Optimal someone has an idea how to repair this html with preg_replace, iterations and/or recursion.

 

If i have tomorrow access on my working environment, i will post further information.

 

 

Kind regards,

 

Butzman.

 

 

/edit:

I need to handle inline-tags (<STRONG><EM><U><STRIKE>). IE creates invalid html by inserting that tags on  '<P> </P>' blocks.

 

My first approach was too search for:

Begins with <INLINETAG>

followed by anything but not </INLINETAG> and not </P></INLINETAG>

followed by </P></INLINETAG>

 

Replace with <INLINETAG>$1</INLINETAG></P>.

 

But i had no success, because i could not create the not </INLINETAG>... expression.

Look-around expression was unsuccessful, too: ($!^(.)*</INLINETAG>(.)*$)

Link to comment
https://forums.phpfreaks.com/topic/198222-repair-ie-rte-html-with-regexp/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.