Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HTML formatting in PHP

Status
Not open for further replies.

BB101

Programmer
May 23, 2001
337
GB
I have assembled a rich text html editor for the web and the code returned
can be quite horrid.

When pasteing from word (as our client wants to), the code returned looks
something like this:

<TABLE style=&quot;BORDER-RIGHT: medium none; BORDER-TOP: medium none;
BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE:
collapse; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0in 5.4pt
0in 5.4pt&quot; cellSpacing=0 cellPadding=0 border=1>

<TR>
<TD style=&quot;BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt;
BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM:
0in; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 6.15in; PADDING-TOP: 0in;
BORDER-BOTTOM: windowtext 0.5pt solid&quot; vAlign=top width=590 colSpan=3>
<P>In Waste Management:</P></TD></TR>
<TR>
<TD style=&quot;BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt;
BORDER-TOP: medium none; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in;
BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 2.05in; PADDING-TOP: 0in;
BORDER-BOTTOM: windowtext 0.5pt solid; mso-border-top-alt: solid windowtext
.5pt&quot; vAlign=top width=197>
<P>Who collects my waste?</P></TD>
<TD style=&quot;BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt;
BORDER-TOP: medium none; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in;
BORDER-LEFT: medium none; WIDTH: 2.05in; PADDING-TOP: 0in; BORDER-BOTTOM:
windowtext 0.5pt solid; mso-border-top-alt: solid windowtext .5pt;
mso-border-left-alt: solid windowtext .5pt&quot; vAlign=top width=197>
<P>Collection Authority</P></TD>
<TD style=&quot;BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt;
BORDER-TOP: medium none; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in;
BORDER-LEFT: medium none; WIDTH: 2.05in; PADDING-TOP: 0in; BORDER-BOTTOM:
windowtext 0.5pt solid; mso-border-top-alt: solid windowtext .5pt;
mso-border-left-alt: solid windowtext .5pt&quot; vAlign=top width=197>
<P>District Councils</P></TD></TR>
<TR>
<TD style=&quot;BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt;
BORDER-TOP: medium none; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in;
BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 2.05in; PADDING-TOP: 0in;
BORDER-BOTTOM: windowtext 0.5pt solid; mso-border-top-alt: solid windowtext
.5pt&quot; vAlign=top width=197>
<P>Who deals with disposal?</P></TD>
<TD style=&quot;BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt;
BORDER-TOP: medium none; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in;
BORDER-LEFT: medium none; WIDTH: 2.05in; PADDING-TOP: 0in; BORDER-BOTTOM:
windowtext 0.5pt solid; mso-border-top-alt: solid windowtext .5pt;
mso-border-left-alt: solid windowtext .5pt&quot; vAlign=top width=197>
<P>Disposal Authority</P></TD>
<TD style=&quot;BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt;
BORDER-TOP: medium none; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in;
BORDER-LEFT: medium none; WIDTH: 2.05in; PADDING-TOP: 0in; BORDER-BOTTOM:
windowtext 0.5pt solid; mso-border-top-alt: solid windowtext .5pt;
mso-border-left-alt: solid windowtext .5pt&quot; vAlign=top width=197>
<P>County Council</P></TD></TR>
<TR>
<TD style=&quot;BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt;
BORDER-TOP: medium none; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in;
BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 2.05in; PADDING-TOP: 0in;
BORDER-BOTTOM: windowtext 0.5pt solid; mso-border-top-alt: solid windowtext
.5pt&quot; vAlign=top width=197>
<P>Who plans for the provision of waste sites?</P></TD>
<TD style=&quot;BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt;
BORDER-TOP: medium none; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in;
BORDER-LEFT: medium none; WIDTH: 2.05in; PADDING-TOP: 0in; BORDER-BOTTOM:
windowtext 0.5pt solid; mso-border-top-alt: solid windowtext .5pt;
mso-border-left-alt: solid windowtext .5pt&quot; vAlign=top width=197>
<P>Planning Authority</P></TD>
<TD style=&quot;BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt;
BORDER-TOP: medium none; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in;
BORDER-LEFT: medium none; WIDTH: 2.05in; PADDING-TOP: 0in; BORDER-BOTTOM:
windowtext 0.5pt solid; mso-border-top-alt: solid windowtext .5pt;
mso-border-left-alt: solid windowtext .5pt&quot; vAlign=top width=197>
<P>County Council</P></TD></TR>
<TR>
<TD style=&quot;BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt;
BORDER-TOP: medium none; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in;
BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 2.05in; PADDING-TOP: 0in;
BORDER-BOTTOM: windowtext 0.5pt solid; mso-border-top-alt: solid windowtext
.5pt&quot; vAlign=top width=197>
<P>Who \'polices\' the waste sites? </P></TD>
<TD style=&quot;BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt;
BORDER-TOP: medium none; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in;
BORDER-LEFT: medium none; WIDTH: 2.05in; PADDING-TOP: 0in; BORDER-BOTTOM:
windowtext 0.5pt solid; mso-border-top-alt: solid windowtext .5pt;
mso-border-left-alt: solid windowtext .5pt&quot; vAlign=top width=197>
<P>Regulation Authority</P>
<P>&nbsp;</P></TD>
<TD style=&quot;BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt;
BORDER-TOP: medium none; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in;
BORDER-LEFT: medium none; WIDTH: 2.05in; PADDING-TOP: 0in; BORDER-BOTTOM:
windowtext 0.5pt solid; mso-border-top-alt: solid windowtext .5pt;
mso-border-left-alt: solid windowtext .5pt&quot; vAlign=top width=197>
<P>Environment Agency</P></TD></TR></TABLE><p></P>

Which is grossly OTT.

I would like to extract all the data from a tag and put back in the buts i
want; i.e, get rid of all properies except things like colspan and rowspan,
etc.

I wrote this simple routine to take out ALL the properties but this mucks up
a lot!

$str = preg_replace(&quot;/<TD([^>]*)>/i&quot;,&quot;<TD>\\1&quot;,$str);
$str = preg_replace(&quot;/<TR([^>]*>)/i&quot;,&quot;<TR>\\1&quot;,$str);
$str = preg_replace(&quot;/<TABLE([^>]*)>/i&quot;,&quot;<TABLE border=1
bordercolor='#666666' cellpadding=3 cellspacing=0>\\1&quot;,$str);

can anyone help?

--BB
 
AFIK html-tidy filters out all this MS-stuff they add to douments written in Word, Excel, ...

Give it a try. cu, Sascha
 
What is HTML-Tidy? where do I read more?

This server is running linux --BB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top