简体   繁体   English

SQL中的特殊字符无法正确显示

[英]Special characters in sql not displaying correctly

I have a string that is stored in a tsql database(the expected string should display "a'string" ) but when I load it into my web browser I see "a'string" same for all the special characters. 我有一个存储在tsql数据库中的字符串(预期的字符串应显示"a'string" ),但是当我将其加载到Web浏览器中时,对于所有特殊字符,我都看到相同的"a'string" The encoding is also saved as "a'string" in the database. 编码也被另存为"a'string"在数据库中。

I'm under the belief that my webpage's encoding is different than my db and this is what is causing the issue. 我相信我的网页编码与我的数据库不同,这就是导致此问题的原因。

after running: 运行后:

SELECT SERVERPROPERTY('Collation')

I see that the encoding is set to SQL_Latin1_General_CP1_CI_AS and I have placed 我看到编码设置为SQL_Latin1_General_CP1_CI_AS ,我已经放置了

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

in the head of my layout page. 在我的布局页面的顶部。

I'm very confident that this is not the correct type, and was looking for some guidance as to how to solve this. 我非常有信心这不是正确的类型,并且正在寻找有关如何解决此问题的指导。

I cannot change anything about my SQL server, this is very locked down and read-only. 我无法更改有关SQL Server的任何内容,这已被锁定并且为只读状态。

This is not a problem of your SQL, most likely your server side code is converting special char to HTML entities using htmlentities. 这不是您的SQL问题,很可能您的服务器端代码正在使用htmlentities将特殊字符转换为HTML实体。 Not sure what language you are using, PHP for example, you can use html_entity_decode to display it correctly. 不确定使用的是哪种语言(例如PHP),可以使用html_entity_decode正确显示它。

$str = "a'string";
echo htmlentities($str,ENT_QUOTES);                                //OUTPUT a&#039;string
echo html_entity_decode(htmlentities($str,ENT_QUOTES),ENT_QUOTES); //OUTPUT a'string

Your database is capable of double-byte, that's not the problem. 您的数据库具有双字节能力,这不是问题。 It appears that you're running into a security measure -- the single-quote being escaped/decoded so that it doesn't go into the database execution as a single quote (which is a string delimiter for SQL). 看来您正在遇到一种安全措施-对单引号进行转义/解码,以便它不会作为单引号进入数据库执行(这是SQL的字符串定界符)。

why "&#39;" 为什么是“&#39;” is not getting converted to single quotes while using server.htmldecode()? 使用server.htmldecode()时不会转换为单引号?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM