1

Possible Duplicate:
PHP to clean-up pasted Microsoft input

Need to remove the code in comments

[if gte mso 9]><xml> <w:WordDocument>  ..... --> [endif] -->

from my db field, when copying text from word and saving this unwanted code is coming.In Ie the source after this was not displaying as it causes display problems

Community
  • 1
  • 1
srikanth s
  • 137
  • 1
  • 2
  • 16

3 Answers3

0

If thats the exact string you would like to clean then you can use something like this

 $clean_string = preg_replace("/(\[if.+?\[endif\]\s{0,}-->)/","",$dirty_string);

Example here

http://ideone.com/cf0MG

Updated ideone link http://ideone.com/08L6L

Jaspreet Chahal
  • 2,759
  • 1
  • 15
  • 17
  • fails in the presence of multiple "comments" in the input string, since .* is greedy and will race to the end of the string, then back up only enough to match. (to the last [endif]). Also, * means 'zero or more' too, and is little more readable than {0,}. – Scott Weaver Feb 23 '12 at 09:15
  • ahh sorry should be +? editing now thanks for pointing it out, and yeah I agree with putting a * there :) – Jaspreet Chahal Feb 23 '12 at 09:23
0

try this:

$clean_string = preg_replace("/(\[if\s.*?\].*?\[endif\]\s*-->/)","",$dirty_string);
Scott Weaver
  • 7,192
  • 2
  • 31
  • 43
-2

Take a look at the paste plugin:

[paste_remove_styles] If true, removes all style information when pasting, regardless of browser type. Pasting from Word 2000 will cause tinyMCE to error. Default is false.

CodeCaster
  • 147,647
  • 23
  • 218
  • 272