php - 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)) ;
解决方案
您可以在将其发布到 PHP 之前尝试删除 javascript 上的标签。
// Store the current selections string/value in a variable and strip it's tags
var content = tinymce.activeEditor.selection.getContent({ format : 'text' });
推荐阅读
- reactjs - 如何在 Typescript 中正确输入应用程序状态?
- mongodb - MongoDB - 查询以获取具有相同关系的所有相关文档
- c++ - 在 C++ 中模拟没有依赖注入的函数内部创建的外部依赖对象
- .net-core - 如何使用错误代码 0x8007000d 解析 IIS 500.19 以运行 .net core 2.2
- java - 从 kotlin 调用的第三方 java 库中的重载解析歧义
- python - 如何将一些行组合成一行
- apache-nifi - 如果我们有多个并行运行的流文件,我们如何知道流何时完成?
- c - “***堆栈粉碎检测到***”与文件读取和写入
- java - 春季测试课无法正常工作
- hibernate - Java.lang.NoClasssDefFoundError:当我通过消息驱动 Bean 类调用休眠会话时出现此异常