PHP preg_replace来删除MS Office样式的html注释 [英] PHP preg_replace to remove MS Office style html comments

查看:181
本文介绍了PHP preg_replace来删除MS Office样式的html注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找一种方法来删除MS Office风格的HTML注释,以及之间的一切。这些格式为:

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

blablabla blablabla

<![endif] - > / code>

<![endif]-->

<! - [if gte mso 9]>

blablabla
blablabla

blablabla blablabla

code><![endif] - >

<![endif]-->

我遇到的问题是,我不想从html中删除所有注释。只有这些MSO样式的注释。任何想法?

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?

推荐答案

尝试

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

它会删除所有< > ....<![endif] - > 注释

这篇关于PHP preg_replace来删除MS Office样式的html注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆