PHP清理粘贴的Microsoft输入 [英] PHP to clean-up pasted Microsoft input

查看:59
本文介绍了PHP清理粘贴的Microsoft输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,用户可以在其中使用TinyMCE的自定义实现发布内容(例如在论坛,评论等中).他们中的许多人都喜欢复制&从Word中粘贴,这意味着它们的输入通常带有大量相关联的MS内联格式.

I have a site where users can post stuff (as in forums, comments, etc) using a customised implementation of TinyMCE. A lot of them like to copy & paste from Word, which means their input often comes with a plethora of associated MS inline formatting.

我不能仅仅摆脱<span whatever>,因为TinyMCE的某些格式依赖于span标签,而且我不能(也不想)强迫用户使用TinyMCE的从Word粘贴" "功能(无论如何似乎效果都不佳).

I can't just get rid of <span whatever> as TinyMCE relies on the span tag for some of it's formatting, and I can't (and don't want to) force said users to use TinyMCE's "Paste From Word" feature (which doesn't seem to work that well anyway).

有人知道可以帮我解决这个问题的库/类/函数吗?尽管我找不到任何确定的信息,但这肯定是一个普遍的问题.我最近一直在思考,寻找MS特定模式的一系列蛮力正则表达式可能会解决问题,但是我不想重写除非我必须的东西.

Anyone know of a library/class/function that would take care of this for me? It must be a common problem, though I can't find anything definitive. I've been thinking recently that a series of brute-force regexes looking for MS-specific patterns might do the trick, but I don't want to re-write something that may already be available unless I must.

此外,固定引号,破折号等也是不错的选择.我现在有我自己的东西可以做,但是我真的很想找到一个MS转换过滤器来统治所有这些.

Also, fixing of curly quotes, em-dashes, etc would be good. I have my own stuff to do this now, but I'd really just like to find one MS-conversion filter to rule them all.

推荐答案

HTML Purifier 将创建符合标准的标记和过滤器排除许多可能的攻击(例如XSS).

HTML Purifier will create standards compliant markup and filter out many possible attacks (such as XSS).

对于不需要XSS过滤的更快清理,我使用了PECL扩展 Tidy ,它是一个整洁的HTML 实用程序的绑定.

For faster cleanups that don't require XSS filtering, I use the PECL extension Tidy which is a binding for the Tidy HTML utility.

如果这些操作没有帮助,我建议您切换到具有此功能的FCKEditor,内置.

If those don't help you, I suggest you switch to FCKEditor which has this feature built-in.

这篇关于PHP清理粘贴的Microsoft输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆