How to split Chinese characters in PHP?

前端 未结 3 1615
南笙
南笙 2021-01-03 13:13

I need some help regarding how to split Chinese characters mixed with English words and numbers in PHP.

For example, if I read

FrontPage 2000中文版應用大全
         


        
3条回答
  •  醉话见心
    2021-01-03 14:14

        /**
         * Reference: http://www.regular-expressions.info/unicode.html
         * Korean: Hangul
         * CJK: Han
         * Japanese: Hiragana, Katakana
         * Flag u required
         */
    
        preg_match_all(
            '/\p{Hangul}|\p{Hiragana}|\p{Han}|\p{Katakana}|(\p{Latin}+)|(\p{Cyrillic}+)/u',
            $str,
            $result
        );
    

    This one is working if you are using PHP 7.0 too.

    This one is just not working. I regret I have upvoted a non-working solution....

    
    

提交回复
热议问题