如何通过php检查字符串中的波斯字符

时间:2017-10-14 20:15:33

标签: php

如何通过php检查字符串中的波斯字符?

见下文

string valid : persian character

string invalid : except persian character(contain: latin && {&*%$ ,....})

1 个答案:

答案 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!
    }
}