PHP - 包含HTML的HTML表单TEXTAREA [英] PHP - HTML Form TEXTAREA containing HTML

查看:148
本文介绍了PHP - 包含HTML的HTML表单TEXTAREA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用HTML表单的TEXTAREA字段,其中包含文本,并可能包含一些HTML标记。
已经阅读,应该使用htmlspecialchars函数,但是这会显示HTML标签,这样很容易将HTML代码编辑成TEXTAREA格式。
为了达到这个目的,更安全,更简单的方法是什么?确保引号和脏的HTML代码不会破坏表单?

I'm using a HTML form's TEXTAREA field that will contain text and it may can contain itself some HTML tags. I have read here that this should be managed using htmlspecialchars function, however this will show the HTML tags in a way it will be quite difficult to allow easy editing of the HTML code into the form TEXTAREA. What is the safer, easier way to achieve this, ensuring that quotes and "dirty" HTML code will not spoil the form?

推荐答案


  1. 为您的用户提供一个Javascript丰富文本编辑器,例如TinyMCE: http://tinymce.moxiecode.com/

  2. 抓取RTE生成的源代码并在保存到数据库之前通过 HTML Purifier 进行过滤。

  3. 转义现有HTML:< div id =myHtmlstyle =display:none><?php echo htmlentities($ html);通过Javascript重新填充RTE - 对于TinyMCE,如下所示: tinyMCE。

activeEditor.setContent($('#myHtml')。html());

  1. Provide a Javascript rich-text editor for your users such as TinyMCE: http://tinymce.moxiecode.com/
  2. Grab the source generated by the RTE and filter it through HTML Purifier before saving to the database.
  3. Escape the existing HTML: <div id="myHtml" style="display: none"><?php echo htmlentities($html); ?></div>
  4. Re-populate the RTE via Javascript - in the case of TinyMCE as follows: tinyMCE.activeEditor.setContent($('#myHtml').html());

通过AJAX加载HTML内容。

You can also load the HTML content via AJAX.

这篇关于PHP - 包含HTML的HTML表单TEXTAREA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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