[英]Regex to avoid stripping IE conditional tags
我在PHP中使用Regex刪除了我的HTML注釋。
$html = preg_replace('/<!--(.*)-->/Uis', '', $html);
但是,我不希望正則表達式刪除我有條件的IE標記
<!--[if lte IE 6]><html class="ie6 no-js">
<!--[if gt IE 8]><!--><html class="no-js"><!--<![endif]-->
<!--[if IE]>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<![endif]-->
有沒有簡單的方法可以做到這一點?
編輯:為方便起見,我在此處添加了相關的HTML代碼: http : //pastebin.com/dPGHHXjU (OR)在此處: https : //regex101.com/r/yS8zM6/1
提前致謝
我從另一篇文章中得到了答案:
$html = preg_replace('~<!--(?!<!)[^\[>].*?-->~s','', $html);
此正則表達式效果很好。 (但我不確定它的作用)
參考: https ://stackoverflow.com/a/11337360/1163642(Allen Pestaluky的回答評論)
我在這里添加了一個演示: https : //regex101.com/r/yS8zM6/2
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.