如何通过php检查字符串中的波斯字符?
见下文
string valid : persian character
string invalid : except persian character(contain: latin && {&*%$ ,....})
答案 0 :(得分:0)
$alphabet = ['الف', 'بِ', 'پِ', '...']; # create an array that contains only Persian characters
$alphabet = array_flip($alphabet); # reverse the array (key <=> value)
$chars = preg_split('/(?<!^)(?!$)/u', $string); # use this regexp to transform string intro array of chars
foreach ($chars as $char)
{
if (!isset($alphabet[$char])) # use isset to check the char in the aplhabet
{
# it's not Persian character!
}
}