如何在 php 中使用正则表达式匹配阿拉伯字母

问题描述 投票:0回答:2

如何在 php 中将阿拉伯字母与正则表达式匹配

我的代码

$name = $_GET("name");

if (arabic letters only and spaces) // using regexp
php regex arabic
2个回答
10
投票

我想你的答案就在这里: 在 PHP 中根据字形检查字符串的语言

if(preg_match("/\p{Arabic}/u", $name])) {
echo 'valid';
} 

0
投票

我使用的是 PHP 版本 7.3.33,以下解决方案对我有用。

if(preg_match("/^[\x{0621}-\x{064A} ]+$/u", $name])) {
 echo 'Yes, it contains Arabic letters only and spaces';
} 
© www.soinside.com 2019 - 2024. All rights reserved.