php-用于检查字符串是否包含中文字符的正则表达式 [英] Php - regular expression to check if the string has chinese chars
本文介绍了php-用于检查字符串是否包含中文字符的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有字符串$str
,我想检查其内容是否包含中文字符(是/否)
I have the string $str
and I want to check if it`s content has Chinese chars or not (true/false)
$str = "赕就可消垻,只有当所有方块都被消垻时才可以过关";
你能帮我吗?
谢谢! 阿德里安
推荐答案
您可以使用Unicode字符类 http://www.regular-expressions.info/unicode.html
You could use a unicode character class http://www.regular-expressions.info/unicode.html
preg_match("/\p{Han}+/u", $utf8_str);
这只是检查是否存在至少一个汉字.如果要匹配完整的字符串,则可能需要对此进行扩展.
This just checks for the presence of at least one chinese character. You might want to expand on this if you want to match the complete string.
这篇关于php-用于检查字符串是否包含中文字符的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文