我想在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