如何覆盖具有“&"字样的文本在HTML中 [英] how to Override the text having "&" in html

查看:78
本文介绍了如何覆盖具有“&"字样的文本在HTML中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题很有趣
我有一些数据存储在数据库中
如文字
我和你
他们和他
美国印度

作为单个文本
当我获取数据时
并在
中显示相同的内容 页面
在&"
之后被修整 正在得到我,他们,美国
等等.

这必须归因于与& nbsp;匹配的语法.
我该如何解决这个问题.

[edit]添加了HTML编码-OriginalGriff [/edit]

My problem is very interesting
I have some data stored in database
as text like
I & YOU
THEY & HE
AMERICA & INDIA

as Single Text
when I am fetching the data
and showing the same in
page
its getting trimmed after the "&"
Am getting I ,THEY,AMERICA
and so on .

This Must be due to the syntax matching with  .
How can I solve this issue.

[edit]HTML encode added - OriginalGriff[/edit]

推荐答案

Vivek,

您确定显示的数据已存储在数据库中吗?实际上,如果您的数据库列是varchar,则必须另存为&以便正确存储和检索.

只需在SSMS的表中编写select * from table(如果使用SQL)并检查.
-Milind
Vivek,

Are you sure the data is stored in the database as you are showing. Actually if your database column is varchar, then you have to save as & for it to store correctly and retrieve.

Just write select * from table in SSMS (if using SQL) and check.
-Milind


Ampersand是HTML中的特殊字符-它引入了一个序列,因此& lt;"例如,显示为<"和&>"作为> -否则您的文本将被浏览器作为标签处理.

根据存储字符串所用的语言,您可以(并且应该)对字符串进行HTML编码,然后再存储它们-否则您的站点很容易受到HTML注入攻击的攻击,并会错误地显示数据.

您没有说您使用什么,所以我们什么也没建议!
Ampersand is a special character in HTML - it introduces a sequence so that "&lt;" for example, is shown as a "<", and "&gt;" as a > - otherwise your text would be processed as a tag by the browser.

Depending on what language you used to store the strings, you could (and should) HTML encode them before you store them - otherwise your site could well be vulnerable to an HTML Injection attack, as well as displaying the data incorrectly.

You don''t say what you use, so we can''t suggest anything!


这篇关于如何覆盖具有“&amp;"字样的文本在HTML中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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