Mysql encounters special characters, resulting in incomplete data

Source: Internet
Author: User
Mysql encounters special characters, causing incomplete data. I serialized the array and stored it in a database field, but some data values in the array contain special characters,

Save it to the database.


There are many special characters like this;

Which of the following has lost some data? Please kindly advise.


Reply to discussion (solution)

What? Special character, after the string base64_encode? Outbound? Look.

What? Special character, after the string base64_encode? Outbound? Look.


[Code = php] $ str = 'longhua


Not to post php code


$ Str = 'longhua


What? Special character, after the string base64_encode? Outbound? Look.


[Code = php] $ str = 'longhua


Me?

Please provide real data

What? Special character, after the string base64_encode? Outbound? Look.


Please provide real data


I don't know what data is missing? Special characters cannot be displayed here.

header('Content-type: text/html;charset=utf-8');$s = '6b6Z5Y2O8K+gpQ==';echo $t = base64_decode($s), PHP_EOL;echo bin2hex($t);
Longhua

header('Content-type: text/html;charset=utf-8');$s = '6b6Z5Y2O8K+gpQ==';echo $t = base64_decode($s), PHP_EOL;echo bin2hex($t);
Longhua



header('Content-type: text/html;charset=utf-8');$s = '6b6Z5Y2O8K+gpTEyMzEyMzEyMw==';echo $t = base64_decode($s), PHP_EOL;echo pack("H*", bin2hex($t));


This won't work ~~ It should not be a space in the middle.

What are you doing?

header('Content-type: text/html;charset=utf-8');$s = '6b6Z5Y2O8K+gpTEyMzEyMzEyMw==';$t = base64_decode($s), PHP_EOL;echo bin2hex($t);
E9be99e58d8e f0afa0a5313233313233313233

Didn't you tell me? It's an emoticons. browsers in the PC do not display them.

Because the front-end cannot block user input, the backend needs to filter out the data before inserting it into the database.
Otherwise, the information displayed in the database is incomplete.

Do not use UTF-8 characters ?? You can.

Header ('content-type: text/html; charset = utf-8 '); $ s = '6b6z5y2o8k + gpTEyMzEyMzEyMw ='; $ t = base64_decode ($ s ). PHP_EOL; echo $ t.'
'; Echo filter_utf8_char ($ t );/**?? String, retain the UTF8 letter? Chinese characters and partial characters? * @ Param String $ ostr * @ return String */function filter_utf8_char ($ ostr) {preg_match_all ('/[\ x {FF00}-\ x {FFEF} | \ x {0000}-\ x {00ff} | \ x {4e00}-\ x {9fff }] +/U ', $ ostr, $ matches); $ str = join ('', $ matches [0]); if ($ str = '') {// The number of characters that contain special characters must be ?? $ Returnstr = ''; $ I = 0; $ str_length = strlen ($ ostr); while ($ I <= $ str_length) {$ temp_str = substr ($ ostr, $ I, 1); $ ascnum = Ord ($ temp_str); if ($ ascnum >=224) {$ returnstr = $ returnstr. substr ($ ostr, $ I, 3); $ I = $ I + 3;} elseif ($ ascnum> = 192) {$ returnstr = $ returnstr. substr ($ ostr, $ I, 2); $ I = $ I + 2;} elseif ($ ascnum >=65 & $ ascnum <= 90) {$ returnstr = $ returnstr. substr ($ ostr, $ I, 1); $ I = $ I + 1;} elseif ($ ascnum >=128 & $ ascnum <= 191) {// Special Character $ I = $ I + 1;} else {$ returnstr = $ returnstr. substr ($ ostr, $ I, 1); $ I = $ I + 1 ;}}$ str = $ returnstr; preg_match_all ('/[\ x {FF00}-\ x {FFEF} |\x {0000}-\ x {00ff} | \ x {4e00}-\ x {9fff}] +/U ', $ str, $ matches); $ str = join ('', $ matches [0]);} return $ str ;}

Longhua

If you do not enter anything at the front-end, you need to save the database. you need to input a limit before saving it. You can communicate with your superiors.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.