在数据库中安全地存储HTML,而不影响字符编码 [英] Safely Store HTML in DB without affecting Character encoding

查看:156
本文介绍了在数据库中安全地存储HTML,而不影响字符编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个字符串并将其存储在MYSQL数据库中。这个字符串将是一个HTML字符串,它可以有任何字符编码或以任何语言编写。



如何安全地保存在我的MYSQL数据库,而不会影响HTML



此外,它将存储的字段是数据类型 text

code>并且有 latin1_swedish_ci 的排序规则会影响它吗?



this:

  htmlentities($ html,ENT_QUOTES,'UTF-8')

但我不认为以上将适用于所有字符集。

解决方案

感谢您的帮助。 / div>

为什么不把base64编码为存储,然后在?


后解码

I want to take a string and store it in a MYSQL db. This string will be a HTML string and it can have any character encoding or be written in any language.

How can I safely save this in my MYSQL DB without affecting the HTML string so that I can later retrieve it as it is?

In addition, the field it will be stored in is of data type text and has a collation of latin1_swedish_ci will this effect it in anyway?

I am currently doing this:

htmlentities($html, ENT_QUOTES, 'UTF-8')

But I don't think the above will work for all character sets. I mean how will German or Japanese characters be affected?

Thanks for any help.

解决方案

Why not base64 encode it for storage, and then decode it after?

这篇关于在数据库中安全地存储HTML,而不影响字符编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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