简体   繁体   English

在数据库中存储特殊字符的最佳方法是什么?

[英]What is the best way to store special character in database?

I have a string that will contain special character. 我有一个包含特殊字符的字符串。

for example
EC-1CF08540B7799143A

Whenever I am trying to store it into database it will save it as 每当我尝试将其存储到数据库时,它将保存为

EC%2d1CF08540B7799143A

What will be the best way to store strings with special characters in mySQL and retrieve the original form using PHP? mySQL使用特殊字符存储字符串并使用PHP检索原始格式的最佳方法是什么?

Check what encoding the database is using, then make sure that the meta tag in your HTML file is also using the same encoding type. 检查数据库使用的编码方式,然后确保HTML文件中的meta标记也使用相同的编码类型。

To find out the encoding of your table, use 要找出表的编码,请使用

SHOW CREATE TABLE mytable;

This will output the create statement for the table, including the encoding ( CHARSET ). 这将输出该表的create语句,包括编码( CHARSET )。

In your HTML head, you should have a line such as 在HTML头中,您应该有如下一行:

<meta charset="UTF-8">

Make sure that the CHARSET in your SQL output matches this or vice-versa. 确保SQL输出中的CHARSET与此匹配,反之亦然。

Ideally, they will both be using UTF-8. 理想情况下,它们都将使用UTF-8。

尝试将特定的列设置为“ urf_general_ci”。

use 采用

<?php
$sting = $_REQUEST['string'];
$new_string = str_replace("%2d", "-", $string);
?>

Now save this $new_sting into database. 现在,将此$ new_sting保存到数据库中。

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

相关问题 在MySQL数据库中存储特殊字符的最佳方法是什么? - What is the best way to store special characters in a MySQL database? 在数据库中存储大量标记的最佳方法是什么? - what is the best way to store a lot of markers in database? 将html数据存储在mysql数据库中的最佳方法是什么? - What's the Best way to store html data in a mysql database? 在mysqli数据库中存储日期和时间的最佳方法是什么? - What is the best way to store date and time in mysqli database? 使用Codeigniter在数据库中存储站点配置/选项的最佳方法是什么? - What is the best way to store site configuration/option in database using Codeigniter? 在数据库中存储多个复选框值并在以后使用它的最佳方法是什么 - What is the best way to store multiple checkbox values in the database and work with it later on 在 MySQL 数据库中存储复选框值的最佳方法是什么? - What's the best way to store Checkbox Values in MySQL Database? 在数据库中存储IP的最佳方法? - Best way to store IP in database? 将特殊字符存储在可由JavaScript和HTML读取的mysql数据库中 - Store special character in mysql database that can be read by JavaScript and HTML 如何强制mySQL数据库存储以下特殊字符:╠? - How can I force mySQL database to store this special character: ╠?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM