PHP preg_replace to remove MS Office style html comments

♀尐吖头ヾ 提交于 2019-12-11 08:19:15

问题


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:


try this

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

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



来源:https://stackoverflow.com/questions/3801803/php-preg-replace-to-remove-ms-office-style-html-comments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!