所有樣式如何要刪除屬性BUT NOT TO REMOVE
的樣式屬性,這是 提供表 - PHP要刪除所有樣式屬性,但不刪除樣式屬性,這在表中可供選擇 - PHP
例如:
<div style="text-align: justify; text-indent: -13.5pt; ><strong>Motion with Constant Acceleration</strong></div>
<table cellspacing="0" cellpadding="0" border="1" style="border: medium none; border-collapse: collapse;">
<tr><td width="114" style="border: 1pt;"><div align="center"> </div></td>
<td width="264" style="border-width: 1pt 1pt 1pt medium;" colspan="2">Data Sheet</td>
<td width="157" style="border-width: 1pt 1pt 1pt medium;"><div align="center"> </div></td>
</tr>
<tr style="height: 0.4in;"><td width="114" style="border-width: medium 1pt 1pt;"><div align="center"> </div></td>
<td width="156" style="border-width: medium 1pt 1pt medium;">Incline angle</td>
<td width="108" style="border-width: medium 1pt 1pt medium;"><div align="center"> </div></td>
<td width="157" style="border-width: medium 1pt 1pt medium;"><div align="center"> </div></td>
</tr>
</table>
我的輸出應該是這樣的(注div標籤):
<div><strong>Motion with Constant Acceleration</strong></div>
<table cellspacing="0" cellpadding="0" border="1" style="border: medium none; border-collapse: collapse;">
<tr><td width="114" style="border: 1pt;"><div align="center"> </div></td>
<td width="264" style="border-width: 1pt 1pt 1pt medium;" colspan="2">Data Sheet</td>
<td width="157" style="border-width: 1pt 1pt 1pt medium;"><div align="center"> </div></td>
</tr>
<tr style="height: 0.4in;"><td width="114" style="border-width: medium 1pt 1pt;"><div align="center"> </div></td>
<td width="156" style="border-width: medium 1pt 1pt medium;">Incline angle</td>
<td width="108" style="border-width: medium 1pt 1pt medium;"><div align="center"> </div></td>
<td width="157" style="border-width: medium 1pt 1pt medium;"><div align="center"> </div></td>
</tr>
</table>
你不應該使用[正則表達式來處理HTML]來(http://stackoverflow.com/問題/ 1732348 /正則表達式匹配開放標籤,除了-XHTML-自足標籤/ 1732454#1732454)。您應該使用適當的HTML解析器,在解析時剝離樣式屬性或移動文檔樹以去除它們。 – outis 2011-06-06 11:01:49