Detect chinese (multibyte) character in the string

后端 未结 2 2068
清歌不尽
清歌不尽 2020-12-14 23:31
$str = \"This is a string containing 中文 characters. Some more characters - 中华人民共和国 \";

How do I detect chinese characters from this string and prin

2条回答
  •  盖世英雄少女心
    2020-12-15 00:14

    I've solved this problem using preg_match and regular expressions:

    $str = "This is a string containing 中文 characters. Some more characters - 中华人民共和国 ";
    
    preg_match(/[\x{4e00}-\x{9fa5}]+.*\-/u, $str, $matches);
    

提交回复
热议问题