Paste from word in TinyMCE problem?



Greetings,

I am having an interesting problem. I am a custom php code with a textarea and TinyMCE installed in it. My users typically paste from word into the TinyMCE textarea. But, the paste from word comes with lot of inline styles that should be removed to make things look nice and consistent with the rest of the web page. How do I do this? Is it even possible?

Sincerely,

Mita



You can use HTMLpurifier (http://htmlpurifier.org/).

If you mean that you want to convert following:

<?php
 
<p style="margin-bottom: 0cm;">Remove inline styles but do not strip PHP tags </p>
?>

to

<?php
 
<p>Remove inline styles but do not strip PHP tags </p>
?>

You want to remove inline styles, but retain html tags, use the following PHP regular expression:

<?php
$text 
preg_replace('#(<[a-z ]*)(style=("|\')(.*?)("|\'))([a-z ]*>)#''\\1\\6'$text);
?>