I read the user's nickname through the interface, but many of the names are special characters, such as these special words designators not into the MySQL database is meaningless. So I want to filter, the name of the character only the Chinese characters and numbers extracted. How to write this in PHP.
Reply content:
I read the user's nickname through the interface, but many of the names are special characters, such as these special words designators not into the MySQL database is meaningless. So I want to filter, the name of the character only the Chinese characters and numbers extracted. How to write this in PHP.
It doesn't make any sense to designators these special characters into MySQL database.
----meaningful, Icon ah, field type try it with varbinary
Actually, it's emoji emoticons that don't exist in MySQL.
This expression is not processed directly stored to mysql5.5 below the version will be error
You can modify the database character set to UTF8MB4 try
There is a range of emoji Unicode extracts on GitHub, and the reference range is matched when filtering.
First of all, these things if it means nothing to you, do not save.
It doesn't matter if you extract the part.
Full access, MySQL is supported, the conversion of the character set is good, UTF8MB4 is the UTF8 superset, backward-compatible, modify this is the most perfect solution.
The next is the code level of transcoding, code, then save, remove to re-code display, can also.
This is the last method, in fact, you just can't save into emoji. Filter out the emoji on the 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.