我想在php中编写一个函数,它将通过mySQL数据库循环并删除所有条件注释。PHP函数preg_replace多行条件注释
我想更换看起来像这样的文字:
<!--[if gte mso 9]><xml> <o:OfficeDocumentSettings> <o:AllowPNG /> </o:OfficeDocumentSettings> </xml><![endif]--><!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:TrackMoves /> <w:TrackFormatting /> <w:DoNotShowRevisions /> <w:DoNotPrintRevisions /> <w:DoNotShowMarkup /> <w:DoNotShowComments /> <w:DoNotShowInsertionsAndDeletions /> <w:DoNotShowPropertyChanges /> <w:PunctuationKerning /> <w:ValidateAgainstSchemas /> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:DoNotPromoteQF /><![endif]-->
这里是我的代码
$content = array('1' => $my_text_with_conditional_quotes)
foreach($content as $id => $v){
print $v .' <br>';
$str = addcslashes(preg_replace("/<!(--)?(?=\[)(?:(?!<!\[endif\]\1>).)*<!\[endif\]\1>/s",'',$v));
print $str . '<br>';
print $id . '<br>';
exit;
}
它不匹配任何东西。我错过了什么?
谢谢你收到那个错误,现在就开始工作吧! – alockwood05 2012-02-13 18:57:10
@AlexLockwood:不客气。 – Toto 2012-02-13 19:36:01