I use interfaces to read user nicknames, but many of the names are special characters. for example, it doesn't make sense to save these special characters into the mysql database. So I want to filter it out. only Chinese characters and numbers are extracted from the name characters. How to write this in PHP.
I use interfaces to read user nicknames, but many of the names are special characters. for example, it doesn't make sense to save these special characters into the mysql database. So I want to filter it out. only Chinese characters and numbers are extracted from the name characters. How to write this in PHP.
Reply content:
I use interfaces to read user nicknames, but many of the names are special characters. for example, it doesn't make sense to save these special characters into the mysql database. So I want to filter it out. only Chinese characters and numbers are extracted from the name characters. How to write this in PHP.
It makes no sense that these special characters are not stored in the mysql database.
---- Meaningful, ICON. use varbinary for the field type.
In fact, emoji is not stored in mysql.
If this type of expression is not processed, an error will be reported if it is directly stored in versions earlier than MySQL.
You can modify the database character set to utf8mb4.
Github has the range for extracting emoji unicode. you can match the range when filtering.
First of all, if these things do not make any sense to you, you can just leave them empty.
It is useless for you to extract the part.
The complete access is supported by mysql, and the character set can be converted. utf8mb4 is the superset of utf8, which is backward compatible. modifying this is the perfect solution.
The second is code-level transcoding, encoding, and saving. It can also be pulled out for reverse encoding and then displayed.
The last step is this method. In fact, you just cannot store it in emoji. If you filter out emoji, it will be OK.
public static function emoji($text) { $clean_text = ""; // Match Emoticons $regexEmoticons = '/[\x{1F600}-\x{1F64F}]/u'; $clean_text = preg_replace($regexEmoticons, '', $text); // Match Miscellaneous Symbols and Pictographs $regexSymbols = '/[\x{1F300}-\x{1F5FF}]/u'; $clean_text = preg_replace($regexSymbols, '', $clean_text); // Match Transport And Map Symbols $regexTransport = '/[\x{1F680}-\x{1F6FF}]/u'; $clean_text = preg_replace($regexTransport, '', $clean_text); // Match Miscellaneous Symbols $regexMisc = '/[\x{2600}-\x{26FF}]/u'; $clean_text = preg_replace($regexMisc, '', $clean_text); // Match Dingbats $regexDingbats = '/[\x{2700}-\x{27BF}]/u'; $clean_text = preg_replace($regexDingbats, '', $clean_text); $regexDingbats = '/[\x{231a}-\x{23ab}\x{23e9}-\x{23ec}\x{23f0}-\x{23f3}]/u'; $clean_text = preg_replace($regexDingbats, '', $clean_text); return $clean_text; }
The source is here