1

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?

0

1 Answer 1

1

try this

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

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

Sign up to request clarification or add additional context in comments.

2 Comments

<!-- [if !mso]> this with white space before [doesnt match
@l2aelba added \s* after <!--

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.