Detect chinese (multibyte) character in the string

后端 未结 2 2060
清歌不尽
清歌不尽 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);
    
    0 讨论(0)
  • 2020-12-15 00:16

    Is PHP storing this as Unicode? If so, at worst you could step through the string, character by character, until you hit those within the Chinese range.

    Check this out too PHP: Unicode - Manual

    0 讨论(0)
提交回复
热议问题