$text = '<p width="50px;" style="padding:0px;"><strong style="padding:0;margin:0;">hello</strong></p><table style="text-align:center"></table>';
$text_2 = preg_replace("/<([a-z][a-z0-9]*)[^>]*?(\/?)>/i",'<$1$2>', $text);
輸出(I給這裏的HTML格式):需要用的preg_replace幫助
<p>
<strong>hello</strong>
</p>
<table></table>
我的問題是所有屬性必須被刪除,但不是屬性屬於表。這就是我期待的了把酷似以下(HTML格式):
<p>
<strong>hello</strong>
</p>
<table style="text-align:center"></table>
我應該需要在上述正則表達式來實現它來修改什麼..
任何幫助會感激和感激....
在此先感謝...
可能重複[php:我如何從html標籤中刪除屬性?](http://stackoverflow.com/questions/770219/php-how-can-i-remove-attributes-from-an-html-tag) – kapa 2011-06-07 09:04:42