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

独自空忆成欢 提交于 2019-11-28 00:53:10

问题


Trying to figure out how to tell whether a string contains any characters in Hebrew with no luck.

How can this be done?


回答1:


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)



回答2:


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);



回答3:


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 />";
}


来源:https://stackoverflow.com/questions/8549012/how-to-tell-if-a-string-contains-characters-in-hebrew-using-php

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