Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/416.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php javascript html编辑器复制/粘贴问题_Php_Javascript_Tinymce - Fatal编程技术网

Php javascript html编辑器复制/粘贴问题

Php javascript html编辑器复制/粘贴问题,php,javascript,tinymce,Php,Javascript,Tinymce,我们运行一些大型目录,用户经常在其中将word文档等内容复制/粘贴到我们的TinyMCE html编辑器中 这方面的问题通常是以下文本被隐藏在我们的网页上: <!-- /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; mso-layout-g

我们运行一些大型目录,用户经常在其中将word文档等内容复制/粘贴到我们的TinyMCE html编辑器中

这方面的问题通常是以下文本被隐藏在我们的网页上:

<!-- /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; mso-layout-grid-align:none; punctuation-wrap:simple; text-autospace:none; font-size:10.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman";} a:link, span.MsoHyperlink {color:blue; text-decoration:underline; text-underline:single;} a:visited, span.MsoHyperlinkFollowed {color:purple; text-decoration:underline; text-underline:single;} p {mso-margin-top-alt:auto; margin-right:0in; mso-margin-bottom-alt:auto; margin-left:0in; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman";} @page Section1 {size:8.5in 11.0in; margin:1.0in 1.25in 1.0in 1.25in; mso-header-margin:.5in; mso-footer-margin:.5in; mso-paper-source:0;} div.Section1 {page:Section1;} -->

是否有TinyMCE插件或其他跨浏览器html编辑器可以自动删除这些内容


或者另一种解决方案是使用一些php正则表达式命令或可以去掉这些注释声明的东西。

我个人会使用php正则表达式命令

$str = preg_replace('/<!--.*?--\>/','',$str);

$str=preg_replace('/多年来我一直在尝试优化这一点

到目前为止,我的最佳解决方案如下:

  • 不要使用根块,布局将实现根布局
  • 不要期望用户理解

    之间的区别,因此将所有内容都视为简单的中断,因为它更容易混淆,更像ms word
  • 仅允许预期的元素
这将是初始化代码

remove_linebreaks : false,
force_br_newlines : true, <?php /* maybe we can behave more like gmail */ ?>
force_p_newlines : false,   <?php /* and preserve all message line breaks */ ?> 
convert_newlines_to_brs : false, <?php /* even so i would not count with it */ ?>
forced_root_block : false

<?php /* explicitly define what will be allowed */ ?>
valid_elements: "h1,h2,h3,br,b,a,i,u,strong/b,em/i,u/span,strike/span,span,span[style],"+
                "sub,sup,a[href|name|anchor|target|title],ul,ol,li,p,object[classid|width|height|codebase|*],"+
                "param[name|value|_value],embed[type|width|height|src|*],"+
                "img[style|longdesc|usemap|src|border|alt=|title|hspace|vspace|width|height|align]",
remove_换行符:false,
force\u br\u新词:对,
force_p_新行:false,
将换行符转换为\u brs:false,
强制\u根\u块:false
有效元素:“h1、h2、h3、br、b、a、i、u、strong/b、em/i、u/span、STREAK/span、span、span[样式],”+
“sub、sup、a[href | name | anchor | target | title]、ul、ol、li、p、object[classid |宽度|高度|代码库|*”+
“参数[name | value | u value],嵌入[type | width | height | src |*],”+
“img[style | longdesc | usemap | src | border | alt=| title | hspace | vspace | width | height | align]”,
然后我有以下后处理功能来删除所有
,并将所有
转换为


,这是我能够开发的最稳定的复制粘贴解决方案

这是后处理功能

setup : function(ed) {
    ed.onPostProcess.add(function(ed, o) {
        // Remove all paragraphs and replace with BR
        o.content = o.content.replace(/<p [^>]+>|<p>/g, '');
        o.content = o.content.replace(/<\/p>/g, '<br />');
    });
},
设置:功能(ed){
ed.onPostProcess.add(函数(ed,o){
//删除所有段落并替换为BR
o、 content=o.content.replace(/]+>/g,”);
o、 content=o.content.replace(//g,
); }); },
请注意,所有这些都只是Javascript过滤,用户将能够快速地将所有不需要的代码传递给服务器。即使此设置可能用于终端管理设置,也可以在服务器端使用
strip_标记
,因为某个地方的人可能会绕过它


希望有帮助!

祝你好运。我看了又看,没发现任何东西,但我像鹰一样看着这篇文章,希望有人能找到一个比手动使用Dreamweaver清理Word混乱更好的解决方案。尝试一下Keckeditor,看看TinyMCE的可能副本似乎有一个“Word粘贴”功能,就像其他WYSIWYG编辑器一样。请参阅副本。要添加到Pekka的评论中,我还看到TinyMCE在Drupal中使用时将“从word粘贴”设置为粘贴的默认行为。似乎是这样的,这是Drupal公开的TinyMCE功能,而不是Drupal extra.perfect,可以尝试一下