Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我目前正在使用这种方法来检测字符串中是否存在任何汉字
if (preg_match("/\p{Han}+/u", $str)) { //made in china }
工作正常,但我还需要检查完整的字符串是否为中文,而不仅仅是检查任何字符是否为中文。我似乎无法弄清楚如何做到这一点,可以用 preg match 来完成吗?
添加^和$限定符:
^
$
if (preg_match("/^\p{Han}+$/u", $str)) { //made in china }