从 PHP 中的 jQuery WYSIWYG 编辑器中删除外部样式
我的所见即所得编辑器有问题。如果用户复制外部文本,则会显示如下内容:
" 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
关于您对 strip_tags() 的查询:
是否有可能使用
并被省略?如果是这样,请将
添加到 strip_tags(),例如Regarding your query about strip_tags():
Is there a chance that
<br/>
is used and being omitted? If so, add<br/>
to strip_tags(), e.g.也许使用 preg_replace 像 http://ideone.com/VjMZY ?
Maybe use preg_replace like http://ideone.com/VjMZY?
我认为 jwysiwg 的问题跟踪器有与浏览器端清理相关的评论。
问题 #32 从 Word 中剥离标签:提及恢复到以前的文本如果粘贴文字格式
<块引用>
因此,我建议观察粘贴事件。粘贴时,检查内容是否包含任何隐藏的 Word 标记。如果是,则提醒用户并将文本恢复到粘贴前的状态。
问题 #23 链接到堆栈溢出:need-pure-jquery-javascript-solution-for-cleaning-word-html-from-text-area
'
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
Issue #23 links to stack overflow: need-pure-jquery-javascript-solution-for-cleaning-word-html-from-text-area
'
以下代码最终对我有用:
您可以在 http://jsfiddle.net/v4LhV 中查看此操作/3/
The following code finally got it working for me:
You can see this in action at http://jsfiddle.net/v4LhV/3/