我试图从HTML页面中删除条件注释语句和任何带有条件语句的XML内容,我使用下面的PHP,但似乎没有删除条件语句和XML内容,regex语句有效吗!?
HTML
...
<link rel=File-List href="filelist.xml">
<!--[if gte mso 9]><xml>
<o:DocumentProperties>
<o:Revision>3</o:Revision>
<o:TotalTime>1</o:TotalTime>
<o:Created>2014-02-14T21:30:00Z</o:Created>
<o:LastSaved>2014-02-14T21:35:00Z</o:LastSaved>
<o:Pages>1</o:Pages>
<o:Words>58</o:Words>
<o:Characters>331</o:Characters>
<o:Lines>2</o:Lines>
<o:Paragraphs>1</o:Paragraphs>
<o:CharactersWithSpaces>388</o:CharactersWithSpaces>
<o:Version>15.00</o:Version>
</o:DocumentProperties>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
</o:OfficeDocumentSettings>
</xml><![endif]-->
<link rel=themeData href="themedata.tx">
...
PHP
$html = preg_replace('/<'?xml[^>]+'/>/im', '', $html);
$html = preg_replace('/<!--'[(.*)']>/is', '', $html);
$html = preg_replace('/<!'[(.*)']-->/is', '', $html);
尝试匹配完整的条件注释:
$html = preg_replace('/<!--'[if gte mso 9']>.*<!'[endif']-->/s', '', $html);
http://sandbox.onlinephpfunctions.com/code/e8a48984f34f2323ae14d72b7c33d3065edd00dc