UTF-8编码时,PHP如何正则匹配中文汉字?亲测可用
这个方法亲测可用,代码如下:
<?php
header("content-type:text/html;charset=utf-8");
$input = "^_^,PHP is the best programming language in the world!";
if (preg_match_all("/([x{4e00}-x{9fa5}]+)/u", $input, $match))
{
var_dump($match);
print("该字符串含有中文");
}
else {
print("该字符串没有中文");
}效果如图:
<?php
header("content-type:text/html;charset=utf-8");
$input = "utf-8编码时,如何正则匹配中文汉字?";
if (preg_match_all("/([x{4e00}-x{9fa5}]+)/u", $input, $match))
{
var_dump($match);
print("该字符串含有中文");
}
else {
print("该字符串没有中文");
}效果截图:
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: 正则验证匹配中文姓名全部源字符串
- 下一篇: 验证中文名字
