PHP preg_replace to remove MS Office style html co

2019-08-05 05:52发布

Im looking for a way to remove MS Office style html comments, and everything in between. These are of the form:

<!--[if gte mso 10]>

blablabla blablabla

<![endif]-->

or

<!--[if gte mso 9]>

blablabla blablabla

<![endif]-->

The problem i'm encountering is that I do not want to remove ALL comments from the html. Only these MSO style comments. Any ideas?

1条回答
太酷不给撩
2楼-- · 2019-08-05 06:38

try this

preg_replace('/<!--\s*\[if[^\]]*]>.*?<!\[endif\]-->/i', '', $string);

it will remove all <!--[if ...]>....<![endif]--> comments

查看更多
登录 后发表回答