My Science Is Better

12Sep/110

Remove MS Word formatting using PHP regular expressions

Recently i've had a client which would only paste into the CMS text from MS Word. Normally a JS should have been in place to automatically strip the crazy tags Word adds, but on this project this was not the case. Here's hos to remove MS Word formatting using PHP regular expressions:

// it will remove all <!--[if ...]>....<![endif]--> comments
preg_replace('/<!--\[if[^\]]*]>.*?<!\[endif\]-->/i', '', $string);

or 

// it will remove all <!--[if ...]>.... --> comments
preg_replace('/<!--\[if[^\]]*]>.*?-->/i', '', $string);
Tagged as: , Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.

Tag Cloud

Categories

Archives

Akismet

Blogroll

Ads