How can I detect Hebrew characters of both iso8859-8 and utf8 in a string using php

I want to be able to detect (using regular expressions) if the string contains Hebrew characters both utf8 and iso8859-8 in the php programming language. thanks!

+5
source share
5 answers

Here is the character set map iso8859-8 . The range E0 - FA appears to be reserved for Hebrew. You can check these characters in a character class:

[\xE0-\xFA]

For UTF-8, the range reserved for Hebrew is from 0591 to 05F4. So you can detect this with:

[\u0591-\u05F4]

Here is an example of regular expression matching in PHP:

echo preg_match("/[\u0591-\u05F4]/", $string);
+14

, PHP UTF-8, , , RegX:

$string="אבהג";
echo preg_match("/\p{Hebrew}/u", $string);
// output: 1
+4

, , :

function IsStringStartsWithHebrew($string)
{
    return (strlen($string) > 1 && //minimum of chars for hebrew encoding
        ord($string[0]) == 215 && //first byte is 110-10111
        ord($string[1]) >= 144 && ord($string[1]) <= 170 //hebrew range in the second byte.
        );
}

:)

+1

-, - ?

iso8859-8 UTF-8 ord($char) > 127. , 127, , is8859-8, , UTF8-...

0
source
function is_hebrew($string)
{
    return preg_match("/\p{Hebrew}/u", $string);
}
0
source

All Articles