Paste from word in TinyMCE problem?

This Comment will be submitted for moderation and will not be accessible to other users until it has been approved.


5 points

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



2 points

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

Anonymous's picture
Created by Anonymous
-3 points

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);
?>

Anonymous's picture
Created by Anonymous

Post Comment

  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.