Home  >  Article  >  php教程  >  匹配中文字符串正则表达式

匹配中文字符串正则表达式

WBOY
WBOYOriginal
2016-06-08 17:26:15995browse

下面这款匹配中文字符串正则表达式是一款利用数组,然后 多次for把全是中文字符串的打印出来。

<script>ec(2);</script>

 

 代码如下 复制代码

$str_arr = array(
"iameverysorry",
"快乐编程,快乐生活",
"php教程编程",
"1997年香港回归",
"英语学习abc",
"www.111cn.net"
);

$patt_ch = chr(0xa1) . "-" . chr(0xff);

foreach ($str_arr as $str)
{
    echo "字符串'$str' 是";
    if (preg_match("/^[$patt_ch]+$/", $str))
    {
        echo "完全中文";
        echo "
";
        echo "
";
    }
    else
    {
        echo "非完全中文";
        echo "
";
        echo "
";
    }
}

/*
字符串'iameverysorry' 是非完全中文

字符串'快乐编程,快乐生活' 是完全中文

字符串'php编程' 是非完全中文

字符串'1997年香港回归' 是非完全中文

字符串'英语学习abc' 是非完全中文

字符串'123456789' 是非完全中文
*/

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn