在MySQL数据库中存储&(Ampersand)的最佳方式 [英] The best way to store &(Ampersand) in MySQL database

查看:441
本文介绍了在MySQL数据库中存储&(Ampersand)的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个类别列表,但我不确定如何将&符号
存储在MySQL数据库中。如果我使用'&',是否有任何问题/缺点?在使用html格式'& amp'

时是否存在差异
?解决方案

使用'&'可以节省几个字节。它不是MySQL的特殊字符。稍后用PHP的方法& amp; rel =noreferrer> htmlspecialchars() 。当你的领域是为了保持简单的信息,你应该只使用纯文本,因为这通常更灵活,因为你以后可以生成不同种类的标记等。例外情况:标记是由用户决定要用文本保存的布局决定(如富文本输入)。如果您在输入中有标签等,则可能需要使用& amp; 来确保一致性。

I'm building a category list and I'm unsure how to store the Ampersand symbol in MySQL database. Is there any problem/disadvantage if I use '&'. Are there any differences from using it in a html format '&amp'?

解决方案

Using '&' saves a few bytes. It is not a special character for MySQL. You can easily produce the & for output later with PHP's method htmlspecialchars(). When your field is meant to keep simple information, you should use plain text only, as this is in general more flexible since you can generate different kinds of markup etc. later. Exception: the markup is produced by a user whose layout decisions you want to save with the text (as in rich-text input). If you have tags etc. in your input, you may want to use & for consistency.

这篇关于在MySQL数据库中存储&(Ampersand)的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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