从 PHP 中的 jQuery WYSIWYG 编辑器中删除外部样式

发布于 2024-09-30 03:44:38 字数 606 浏览 0 评论 0原文

我的所见即所得编辑器有问题。如果用户复制外部文本,则会显示如下内容:

" p.p1 {边距:0.0px 0.0px 0.0px 0.0 像素;字体:11.0px 'Lucida Grande';最小高度:13.0px} p.p2 {边距: 0.0 像素 0.0 像素 0.0 像素 0.0 像素; font: 11.0px 'Lucida Grande'} 仅变量 在最后一个循环中分配的是 从范围之外可以访问 foreach 循环。”

这显然是有问题的。

除此之外,换行符似乎也存在问题,即
标签。有时它们会被拾取,有时则不会我

一直通过 strip_tags() 运行内容,如下所示:

<?php
$body = strip_tags($body, '<a><br><b><i><img><ul><ol><li>');

对这里发生的事情有什么想法吗?

如果有帮助,我将使用 jWYSIWYG 作为编辑器。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

小鸟爱天空丶 2024-10-07 03:44:38

关于您对 strip_tags() 的查询:

php > $str="<br><br/><br />";
php > echo strip_tags($str, "<br>");
<br><br />

是否有可能使用
并被省略?如果是这样,请将
添加到 strip_tags(),例如

php > $str="<br><br/><br />";
php > echo strip_tags($str,'<br><br/>');
<br><br/><br />

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 />
夜未央樱花落 2024-10-07 03:44:38

也许使用 preg_replace 像 http://ideone.com/VjMZY

$str = preg_replace('/<br[^\>]*?>/', '', $str);

Maybe use preg_replace like http://ideone.com/VjMZY?

$str = preg_replace('/<br[^\>]*?>/', '', $str);
星光不落少年眉 2024-10-07 03:44:38

我认为 jwysiwg 的问题跟踪器有与浏览器端清理相关的评论。

I think the issue tracker for jwysiwg has comments related to this for browser side cleanup.

薄荷港 2024-10-07 03:44:38

以下代码最终对我有用:

$('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);
    });
});

您可以在 http://jsfiddle.net/v4LhV 中查看此操作/3/

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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文