数据库中的不良做法或良好做法的HTML标签? [英] HTML tags in database bad practice or good practice?

查看:130
本文介绍了数据库中的不良做法或良好做法的HTML标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时候,我需要格式化来自数据库的特定数据或它的一部分。

Sometimes I need to format specific data or part of it that comes from the database .

例如:

如果我有一个递减(存储在DB)是这样的:

If i have a desc (stored in DB) like this :

HTML 4已经调整,延伸和增强超出其最初的范围,带来高层次的互动性和多媒体网站。如Flash,Silverlight和Java的插件添加的媒体整合到Web,但并非没有一定的成本。

和我想格式化的最后一行,更改,例如字体和颜色。

and i wanna to format the last line , change the font and color for example .

有什么要做到这一点的最佳做法?

What 's the best practice to do this ?

嵌入 HTML 在我的数据库?标签这是安全和最佳实践还是存在的一些方法来从presentation层结构层分离开来行为层?

embedding HTML tags in my database ??Is this safe and the best practice or there 's some way to separate the structure layer from the presentation layer from the behavior layer ?

推荐答案

如果您打算操纵或搜索所存储的数据,那么HTML标记不存储在数据库中。试想一下,在某些时候你被要求更改从宋体字体格鲁吉亚,变更< B> 标记<强> 或允许用户对HTML柱搜索;和搜索的强烈结束返回不相关的信息,由于强也是一个常用的HTML标记。

If you plan to manipulate or search upon the stored data then do not store HTML markup in your database. Imagine that at some point you're asked to change the fonts from Tahoma to Georgia, change <b> tags to <strong> or allow the users to search on the HTML column; and searches for strong end up returning irrelevant information because strong is also a frequently used HTML tag.

在你的数据库中存储的HTML标记也是,如果你不检查被存储什么坏主意。恶意脚本标记,如&LT;脚本&GT;位置=的http:// otherwebsite'&LT; / SCRIPT&GT; 只是一个简单的例子

Storing HTML markup in your database is also a bad idea if you do not check what is being stored. A malicious script tag such as <script>location = 'http://otherwebsite'</script> is just one naive example.

在理想情况下,你应该存储数据原样或使用某种类型的标记,如(维基或降价)来存储基本的格式信息。

Ideally you should store the data as-is or use some kind of markup such as (wiki or markdown) to store basic formatting information.

这篇关于数据库中的不良做法或良好做法的HTML标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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