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.