如何在 php 中将阿拉伯字母与正则表达式匹配
我的代码
$name = $_GET("name");
if (arabic letters only and spaces) // using regexp
我想你的答案就在这里: 在 PHP 中根据字形检查字符串的语言
if(preg_match("/\p{Arabic}/u", $name])) {
echo 'valid';
}
我使用的是 PHP 版本 7.3.33,以下解决方案对我有用。
if(preg_match("/^[\x{0621}-\x{064A} ]+$/u", $name])) {
echo 'Yes, it contains Arabic letters only and spaces';
}