首页 > 解决方案 > strip_tags 和 tinymce 问题

问题描述

我在使用 strip_tags 清理来自 tinymce 的文本中的 html 标签时遇到问题。我有一个表单,其中一些 textarea 字段由 tinymce 和其他简单输入文本管理。

我需要从这些字段中的某些输入中去除 HTML 标记。这适用于标准输入文本,来自 Tinymce 的文本不会发生任何事情。这是代码的一部分:

//from input text

$title = $_POST['title'] ;

//from  text area loaded by tynymce

$shortcontent = $_POST['shortcontent'] ;
$content = $_POST['content'] ;

$title = strip_tags($title) ;   // works

$content = strip_tags($content) ;  //fail

与此同时,解决了。

简单地说,WYSE 模式下的标签插入总是被编码的,所以 html_entity_decode() 在剥离标签之前

$content = strip_tags(html_entity_decode($content)) ;

标签: phptinymcestrip-tags

解决方案


您可以在将其发布到 PHP 之前尝试删除 javascript 上的标签。

// Store the current selections string/value in a variable and strip it's tags
var content = tinymce.activeEditor.selection.getContent({ format : 'text' });

推荐阅读