How to tell if a string contains characters in Hebrew using PHP?

喜夏-厌秋 提交于 2019-11-29 07:39:11

If the source string is UTF-8 encoded, then the simpler approach would be using \p{Hebrew} in the regex.

The call also should have the /u modifier.

 = preg_match("/\p{Hebrew}/u", $string)

map of the iso8859-8 character set. The range E0 - FA appears to be reserved for Hebrew.

[\xE0-\xFA]

For UTF-8, the range reserved for Hebrew appears to be 0590 to 05FF.

[\u0590-\u05FF]

Here's an example of a regex match in PHP:

echo preg_match("/[\u0590-\u05FF]/", $string);

The simplest approach would be:

preg_match('/[א-ת]/',$string)

For example,

$strings = array( "abbb","1234","aabbאאבב","אבבבב");

foreach($strings as $string)
{
    echo "'$string'  ";

    echo (preg_match('/[א-ת]/',$string))? "has Hebrew characters in it." : "is not Hebrew";

    echo "<br />";
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!