Tuesday, May 27, 2008

how to detecet is there persian alphabet(s) in a string via php?

Because our system should detect direction of a string, we need a function that tell us the string has Persian alphabet or no,
so i write a little function to check it for us:

function hasPersianAlphabet($str) {
$persianAlphabet = array('ا', 'ب', 'پ',
'ت', 'ث', 'ج', 'چ', 'ح', 'خ', 'د',
'ذ', 'ر', 'ز', 'ژ', 'ط', 'ظ', 'س',
'ش', 'ض', 'ص', 'ع', 'غ', 'ف', 'ق',
'ك', 'ک', 'گ', 'ل', 'م', 'ن', 'و',
'ه', 'ي', 'ی', 'ه', 'آ', 'ء', 'ئ', 'ة');
str_ireplace($persianAlphabet, '', $str, $count);
return $count > 0;
}

Labels: , , ,

0 Comments:

Post a Comment

<< Home