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("该字符串没有中文"); }
效果截图:
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
- 上一篇: 谈一谈array_pop和end有什么差别?
- 下一篇: TP5与TP3.X大对比