问题描述
我使用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?
推荐答案
- 为您的用户提供一个Javascript丰富文本编辑器,例如TinyMCE:
- 抓取RTE生成的源代码并在保存到数据库之前通过进行过滤。
- 转义现有HTML:
activeEditor.setContent($('#myHtml')。html());
- Provide a Javascript rich-text editor for your users such as TinyMCE: http://tinymce.moxiecode.com/
- Grab the source generated by the RTE and filter it through HTML Purifier before saving to the database.
- Escape the existing HTML: <div id="myHtml" style="display: none"><?php echo htmlentities($html); ?></div>
- 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!