简体   繁体   中英

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?

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.

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 ).

In your HTML head, you should have a line such as

<meta charset="UTF-8">

Make sure that the CHARSET in your SQL output matches this or vice-versa.

Ideally, they will both be using UTF-8.

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

use

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

Now save this $new_sting into database.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM