[英]Storing ™ within database, but also account for the entity
I have got an issue within saving the ™/© symbol within my database.在我的数据库中保存 ™/© 符号时遇到问题。
The main issue is that some people will simply paste in the symbol (™, ©), whereas other users will use the correct HTML safe code ( ™
, ©
)主要问题是有些人会简单地粘贴符号 (™, ©),而其他用户将使用正确的 HTML 安全代码( ™
, ©
)
This is an issue when attempting to use htmlentities
to convert the symbols to the correct code, as if they use ™
当尝试使用htmlentities
将符号转换为正确的代码时,这是一个问题,就好像它们使用™
this function will convert it to ™
此函数会将其转换为™
. .
Does anyone know a solution to this?有谁知道这个问题的解决方案?
For example detect if the entity was used, if so then I can use htmlentities
to convert it.例如检测实体是否被使用,如果是,那么我可以使用htmlentities
来转换它。
First, set expectations .首先,设定预期。
Your code should expect either plain text or HTML.您的代码应该是纯文本或 HTML。 Your documentation should tell the users which.您的文档应该告诉用户是哪个。
Second, allow people to correct mistakes .第二,允许人们纠正错误。
If a user enters ™
如果用户输入™
into a field that expects plain text then it should be treated as &trade
.进入一个需要纯文本的字段,那么它应该被视为&trade
。
Show the user a preview.向用户显示预览。
Allow them to edit it after submitting.允许他们在提交后对其进行编辑。
Trying to use heuristics to guess if the user wanted to display ™
尝试使用启发式方法来猜测用户是否想要显示™
or ™
is going to lead to false positives.或™
将导致误报。 So don't.所以不要。
Finally, we don't live in the 1980s.最后,我们不是生活在 1980 年代。 We have Unicode now .我们现在有了 Unicode 。 There is no need to encode ™
as ™
无需将™
编码为™
. . So if you are accepting HTML, then just display ™
without encoding it.因此,如果您接受 HTML,则只需显示™
而不对其进行编码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.