Now the mobile side provides a lot of expressions, such as Baidu Input method in the expression.
A lot of expressions in PHP, after it is not recognized content, when stored in MySQL, it will start from the expression position, the contents of the back will be lost.
such as user input: Start content [Emoticons] End content
Get it in PHP and save it in MySQL only: start content [
Is there any way to remove these unrecognized expressions without affecting the content behind them?
For example, if the expression above is not recognized, it also wants to be able to be stored in MySQL: start content [] End content
Reply to discussion (solution)
Required to set the MySQL character set to Utf8mb4
If it is utf8_general_ci, can it be changed directly to UTF8MB4?
In addition, in myphpadmin, can not see UTF8MB4, how to change?
Seems to be the version is not enough, it seems to upgrade to more than 5.5, good trouble ah
No upgrade is OK
Before warehousing
$text = Preg_replace_callback ('/[\xf0-\xf7].{ 3}/', function ($r) {return ' @E '. Base64_encode ($r [0]);}, $text);
After the library
$text = Preg_replace_callback ('/@e (. { 6}==)/', function ($r) {return Base64_decode ($r [1]);}, $text);
No upgrade is OK
Before warehousing
$text = Preg_replace_callback ('/[\xf0-\xf7].{ 3}/', function ($r) {return ' @E '. Base64_encode ($r [0]);}, $text);
After the library
$text = Preg_replace_callback ('/@e (. { 6}==)/', function ($r) {return Base64_decode ($r [1]);}, $text);
Thank you moderator, I try
No upgrade is OK
Before warehousing
$text = Preg_replace_callback ('/[\xf0-\xf7].{ 3}/', function ($r) {return ' @E '. Base64_encode ($r [0]);}, $text);
After the library
$text = Preg_replace_callback ('/@e (. { 6}==)/', function ($r) {return Base64_decode ($r [1]);}, $text);
Not familiar with the regular expression, with the moderator of the method, if I just want to filter out these emoticons, then return to write a return ';
Will you remove some of the other symbols?
$text = Preg_replace_callback ('/[\xf0-\xf7].{ 3}/', function ($r) {return ';}, $text);
$text = Preg_replace_callback ('/[\xf0-\xf7].{ 3}/', function ($r) {return ';}, $text);
Roger that, thanks. Moderator