[英]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.