从ckeditor获取纯文本

时间:2014-05-08 16:39:27

标签: php ckeditor plaintext vtiger

当我提交带有ckeditor textarea的表单时,我想知道是否可以获得纯文本(没有HTML代码的文本)。

事实上,我想要一个带有ckeditor的拼写检查选项的简单textarea。

P.S。我正在使用vtiger 6。

2 个答案:

答案 0 :(得分:0)

您可以使用PHP函数从字符串strip_tags中删除HTML标记:

$plaintext = strip_tags($_POST['mytexteditor']);

您还可以允许某些标记:

$plaintext_with_ps = strip_tags($_POST['mytexteditor'], '<p>');

不要试图将其用作安全措施。

答案 1 :(得分:0)

这是可能的,并且鉴于你正在使用PHP,一个体面的解决方案将是HTML Purifier.假设你可以通过PEAR安装它(这是最简单的方法),你的例子看起来像:

require_once 'HTMLPurifier.auto.php';
$config = HTMLPurifier_Config::createDefault();
$config->set('HTML', 'Allowed', ''); // Allow Nothing
$purifier = new HTMLPurifier($config);
return $purifier->purify($_REQUEST['field_name']);

您还希望从CKeditor中删除大多数编辑器按钮和其他选项,以防止您的用户添加大量无法过滤的格式化。

<强>然而

使用完整的CKEditor堆栈进行拼写检查是错误的!为什么不使用独立的jQuery拼写检查程序like this one?

相关问题