Reputation: 15028
I have an issue with my WYSIWYG editor. If users copy in outside text, this is seen as something like the following:
" p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px 'Lucida Grande'; min-height: 13.0px} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px 'Lucida Grande'} Only the variables assigned in the last loop are accessible from outside the scope of a foreach loop."
This is obviously problematic.
On top of that, there also seems to be an issue with line breaks, i.e. <br />
tags. Sometimes they're picked up, sometimes not.
I've been running the content through strip_tags()
like so:
<?php
$body = strip_tags($body, '<a><br><b><i><img><ul><ol><li>');
Any thoughts on what's going on here?
If it helps, I'm using jWYSIWYG for the editor.
Upvotes: 2
Views: 1126
Reputation: 15028
The following code finally got it working for me:
$('iframe').ready(function() {
$(this).contents().find('.wysiwyg').find('iframe').contents()
.find('.wysiwyg').bind('paste', function() {
// Completely strips tags. Taken from Prototype library.
var el = $(this);
var strClean = el.text().replace(/<\/?[^>]+>/gi, '');
el.text(strClean);
}, 0);
});
});
You can see this in action at http://jsfiddle.net/v4LhV/3/
Upvotes: 0
Reputation: 1155
I think the issue tracker for jwysiwg has comments related to this for browser side cleanup.
Issue #32 stripping tags from Word: mentions reverting to previous text if word formats get pasted
So instead I suggest observing for a paste event. On paste, check if the content contains any hidden Word markup. If yes, alert the user and restore the text to its pre-paste state.
Upvotes: 0
Reputation: 1477
Maybe use preg_replace like http://ideone.com/VjMZY?
$str = preg_replace('/<br[^\>]*?>/', '', $str);
Upvotes: 0
Reputation: 5062
Regarding your query about strip_tags():
php > $str="<br><br/><br />";
php > echo strip_tags($str, "<br>");
<br><br />
Is there a chance that <br/>
is used and being omitted? If so, add <br/>
to strip_tags(), e.g.
php > $str="<br><br/><br />";
php > echo strip_tags($str,'<br><br/>');
<br><br/><br />
Upvotes: 2