How to check if $string contains Hebrew characters?
| From: | Nitsan Bin-Nun | Date: | Wed, 25 Jun 2008 15:33:05 +0000 |
| Subject: | How to check if $string contains Hebrew characters? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-275943@lists.php.net to get a copy of this message | ||
Hi,
I have a $string and i want to know if it contains Hebrew characters in it,
I wrote the following:
> function containHebrewChars ($string)
> {
> $chars = "אבגדהוזחטיכלמנסעפצקרשת"; // ABC of hebrew chars
> (AlefBet)
> $chars =
> preg_replace("/([\xE0-\xFA])/e","chr(215).chr(ord(\${1})-80)",$chars); //
> convert it to UTF8
> if (preg_match("/[".$chars."]/", $string)) return true;
> return false;
> }
>
I'm pretty sure there is a better way to do this (regex is overkill), any
ideas?
Regards,
Nitsan