PHP extracts kanji letters and numbers from a string

Source: Internet
Author: User

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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.