如何允许的意见或任何简单的HTML标签? [英] How to allow simple HTML tags in comments or anywhere?

查看:206
本文介绍了如何允许的意见或任何简单的HTML标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的web应用程序,我开发一个评论的功能,在这里用户可以发表评论。但我面临的一个问题,就是我想允许在留言框中简单的HTML标签。 HTML标签,如< B&GT中,<强&GT中,< I&GT中,< EM&GT中,< U> 等,在正常情况允许进入在评论框。但是,我也希望当用户presses输入,然后它会自动转换成符(< BR /> 标签),并获得存储到数据库中,从而使当我将在网页上显示它们那么他们会像为用户输入。

In my web application I am developing a comment functionality, where user's can comment. But I am facing a problem which is I want to allow simple HTML tags in the comment box. HTML tags like <b>, <strong>, <i>, <em>, <u>, etc., that are normally allowed to enter in a commenting box. But then I also want when user presses enter then it will be automatically converted into breaks (<br /> tags) and get stored into database, so that when I'll display them in the web page then they'll look like as user entered.

能否请你告诉我如何解析用户输入只允许设置的HTML标签和如何转换进入&LT; BR /&GT; 标签,然后存储它们在数据库中。

Can you please tell me how to parse that user entered only allowed set of HTML tags and how to convert enters into <br /> tags and then store them in database.

或者,如果任何人有一些更好的意见或建议来实现这种功能。我使用ASP.NET 2.0(C#)

Or if anyone have some better idea or suggestion to implement this kind of functionality. I am using ASP.NET 2.0 (C#)

我注意到,StackOverflow.com正在做配置文件编辑同样的事情。当我们编辑则低于我们的配置文件中的关于我场的基本HTML允许行写,我想这样做几乎相同的功能。

I noticed that StackOverflow.com is doing the same thing on Profile Editing. When we edit our profile then below the "About Me" field "basic HTML allowed" line is written, I want to do almost the same functionality.

推荐答案

我没有给你一个C#具体的答案,但你可以去一下几种不同的方式。一个是让任何他们想要的用户输入,然后运行一个过滤器在它来剔除坏的HTML。有许多开放源码的过滤器,对于PHP,Python等做到这一点。在一般情况下,这是一个pretty难的问题,而且最好让一些发达的第三方code做到这一点,而不是自己动手写。

I don't have a C# specific answer for you, but you can go about it a few different ways. One is to let the user input whatever they want, then you run a filter over it to strip out the "bad" html. There are numerous open source filters that do this for PHP, Python, etc. In general, it's a pretty difficult problem, and it's best to let some well developed 3rd party code do this rather than write it yourself.

来处理它的另一种方法是让用户在某种像BB code,纺织,或降价更简单的标记语言输入注释(计算器使用降价),也许是一个不错的JavaScript编辑器一起使用。然后运行通过处理器用户的文本,这些标记语言来获得HTML中的一个。您通常可以获取这些处理器对任何一种语言,您正在使用的实现。这些处理器通常剥离出坏的HTML。

Another way to handle it is to allow the user to enter comments in some kind of simpler markup language like BBCode, Textile, or Markdown (stackoverflow is using Markdown), perhaps in conjunction with a nice Javascript editor. You then run the user's text through a processor for one of these markup languages to get the HTML. You can usually obtain implementations of these processors for whatever language you are using. These processors usually strip out the "bad" HTML.

这篇关于如何允许的意见或任何简单的HTML标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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