我已经在这里搜索并找到了与这篇文章相关的类似帖子,但我还没有找到解决方案。
\n\n我试过这个:
\n\n$text = "\xd8\xa7\xd9\x84\xd8\xad\xd9\x85\xd8\xaf \xd9\x84\xd9\x84\xd9\x87 \xd8\xb1\xd8\xa8 \xd8\xa7\xd9\x84\xd8\xb9\xd8\xa7\xd9\x84\xd9\x85\xd9\x8a\xd9\x86 hello";\n\necho $is_arabic = preg_match(\'/\\p{Arabic}/u\', $text);\nRun Code Online (Sandbox Code Playgroud)\n\n我添加了 unicode 标志,但如果我添加任何英文字符,它将返回 true !有什么解决办法吗?
\n\n大家有什么想法吗?
\n\n提前致谢
\n使用 unicode 标志:
\n\n$text = "\xd8\xa7\xd9\x84\xd8\xad\xd9\x85\xd8\xaf \xd9\x84\xd9\x84\xd9\x87 \xd8\xb1\xd8\xa8 \xd8\xa7\xd9\x84\xd8\xb9\xd8\xa7\xd9\x84\xd9\x85\xd9\x8a\xd9\x86";\necho $is_arabic = preg_match(\'/\\p{Arabic}/u\', $text);\n here __^\nRun Code Online (Sandbox Code Playgroud)\n\n如果您只想匹配阿拉伯语,您应该这样做:
\n\necho $is_arabic = preg_match(\'/^[\\s\\p{Arabic}]+$/u\', $text);\nRun Code Online (Sandbox Code Playgroud)\n