IOS input emojimysql cannot be stored (utf8mb4 cannot be changed online). How can I determine whether the input character contains emoji and then prompt that the IOS input emoji mysql cannot be stored (utf8mb4 cannot be changed online ), how to determine whether the input character contains emoji and then prompt
Reply content:
IOS input emoji mysql cannot be stored (utf8mb4 cannot be changed online). How can I determine whether the input character contains emoji and then prompt
You do not need to determine whether it is emoji. The transmitted data is encrypted with json_encode and then stored in the database. Then, you can use json_decode to display the data and urlencode before json_decode, urldecode When retrieving the data;
Before database storage
$message = json_encode($message);
After removal
$message = json_decode($message)
Code:
$ Regex = '/([0-9 | #] [\ x {20E3}]) | [\ x {00ae} | \ x {00a9} | \ x {203C} | \ x {2047} | \ x {2048} | \ x {2049} | \ x {3030} | \ x {303D} | \ x {2139} | \ x {2122} | \ x {3297} | \ x {3299}] [\ x {FE00} -\ x {FEFF}]? | [\ X {2190}-\ x {21FF}] [\ x {FE00}-\ x {FEFF}]? | [\ X {2300}-\ x {23FF}] [\ x {FE00}-\ x {FEFF}]? | [\ X {2460}-\ x {24FF}] [\ x {FE00}-\ x {FEFF}]? | [\ X {25A0}-\ x {25FF}] [\ x {FE00}-\ x {FEFF}]? | [\ X {2600}-\ x {27BF}] [\ x {FE00}-\ x {FEFF}]? | [\ X {2900}-\ x {297F}] [\ x {FE00}-\ x {FEFF}]? | [\ X {2B00}-\ x {2BF0}] [\ x {FE00}-\ x {FEFF}]? | [\ X {1F000}-\ x {1F6FF}] [\ x {FE00}-\ x {FEFF}]? /U'; var_dump (preg_match ($ regex ,'? '); Var_dump (preg_match ($ regex ,'? '); Var_dump (preg_match ($ regex ,'? '); Var_dump (preg_match ($ regex, 'test'); var_dump (preg_match ($ regex, 'Hello, World'); var_dump (preg_match ($ regex, 'testing'); var_dump (preg_match ($ regex, 'Chinese English '));
Result:
int(1)int(1)int(1)int(0)int(0)int(0)int(0)
The expression is found. You can check the range of emoji in the utf8 code table (or convert the range from unicode code table to utf8)
However, we recommend that you change utf8mb4. This migration is basically painless. Just perform a full test.
The fundamental solution is that the database supports emoji.
Are you sure you don't want to store emoji in the database, but detect it and then prompt?
Detection
// If true is returned, emojifunction testEmoji ($ str) {$ text = json_encode ($ str) is returned ); // exposes unicode return preg_match ("/(\ u [ed] [0-9a-f] {3})/I", $ text );}
Escape and save to database
Look at my previous problems, http://segmentfault.com/q/1010000003711491.