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

前端 未结 3 996
我在风中等你
我在风中等你 2020-12-18 03:53

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

How can this be done?

3条回答
  •  余生分开走
    2020-12-18 04:34

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

提交回复
热议问题