How does PHP handle emoticon characters submitted by mobile terminals? At present, mobile terminals provide a lot of emojis, such as those in Baidu's input method.
Many expressions are unidentifiable after they are obtained using php. when stored in mysql, the content starting from the expression position will be lost.
For example, if you enter the start content [emoticons] end content
When you use php to obtain and store data in mysql, you can only save: start content [
Is there any way to delete unrecognized emoticon without affecting the subsequent content?
For example, if the above expression cannot be identified, what you want to save to mysql is: start content [] end content
Reply to discussion (solution)
Set the mysql character set to utf8mb4.
If it is utf8_general_ci, can it be changed to utf8mb4 directly?
In addition, you cannot see utf8mb4 in myphpadmin. how can I modify it?
It seems that the version is not enough. it seems that you want to upgrade to version 5.5 or above, which is troublesome.
Do not upgrade
Before warehouse receiving
$ Text = preg_replace_callback ('/[\ xf0-\ xf7]. {3}/', function ($ r) {return' @ e '. base64_encode ($ r [0]) ;}, $ text );
After warehouse picking
$ Text = preg_replace_callback ('/@ E (. {6 }=)/', function ($ r) {return base64_decode ($ r [1]) ;}, $ text );
Do not upgrade
Before warehouse receiving
$ Text = preg_replace_callback ('/[\ xf0-\ xf7]. {3}/', function ($ r) {return' @ e '. base64_encode ($ r [0]) ;}, $ text );
After warehouse picking
$ Text = preg_replace_callback ('/@ E (. {6 }=)/', function ($ r) {return base64_decode ($ r [1]) ;}, $ text );
Thank you for your consideration.
Do not upgrade
Before warehouse receiving
$ Text = preg_replace_callback ('/[\ xf0-\ xf7]. {3}/', function ($ r) {return' @ e '. base64_encode ($ r [0]) ;}, $ text );
After warehouse picking
$ Text = preg_replace_callback ('/@ E (. {6 }=)/', function ($ r) {return base64_decode ($ r [1]) ;}, $ text );
I am not familiar with regular expressions and use the method given by the moderator. if I just want to filter out these emojis, then return will be written as return ''; is that all right?
Will some other symbols be removed?
$ Text = preg_replace_callback ('/[\ xf0-\ xf7]. {3}/', function ($ r) {return '';}, $ text );
$ Text = preg_replace_callback ('/[\ xf0-\ xf7]. {3}/', function ($ r) {return '';}, $ text );
Thank you, moderator.