Home  >  Q&A  >  body text

怎么使用正则表达式来表示中文?

怎么使用正则表达式来表示中文?

大神,求带!大神,求带!2739 days ago778

reply all(2)I'll reply

  • 数据分析师

    数据分析师2017-10-01 00:15:48

    How to use regular expressions to represent Chinese? -PHP Chinese website Q&A-How to use regular expressions to represent Chinese? -PHP Chinese website Q&A

    Let’s take a look and learn.

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-02-13 10:07:19

    由于中文的ASCII码是有一定的范围的。所以你可以用下面的正则表达式来表示中文。

    /^[chr(0xa1)-chr(0xff)]+$/

    下面是一个使用的例子:

    $str = "超越PHP";
    if (preg_match("/^[".chr(0xa1)."-".chr(0xff)."]+$/", $str)) {
    echo "这是一个纯中文字符串";
    } else {
    echo "这不是一个纯中文字串";
    }


    reply
    0
  • Cancelreply