开发者

PHP preg_replace to remove MS Office style html comments

开发者 https://www.devze.com 2023-01-17 12:49 出处:网络
Im looking for a way to remove MS Office style html comments, and everything in between. These are of the form:

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?


try this

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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消