php匹配中文字符



$str = '写一个hello world程序';

//GBK/GB2312使用:
$result = preg_match_all("/[\x80-\xff]+/", $str, $matches);

// UTF-8 使用:
$result = preg_match_all("/[\x{4e00}-\x{9fa5}]+/u", $str, $matches);

echo '<pre>';print_r($matches);exit;


结果都是:


Array
(
    [0] => Array
        (
            [0] => 写一个
            [1] => 程序
        )

)


你可能感兴趣的:(php匹配中文字符)